15bebb993Sopenharmony_ci/* 25bebb993Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35bebb993Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45bebb993Sopenharmony_ci * you may not use this file except in compliance with the License. 55bebb993Sopenharmony_ci * You may obtain a copy of the License at 65bebb993Sopenharmony_ci * 75bebb993Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85bebb993Sopenharmony_ci * 95bebb993Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105bebb993Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115bebb993Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125bebb993Sopenharmony_ci * See the License for the specific language governing permissions and 135bebb993Sopenharmony_ci * limitations under the License. 145bebb993Sopenharmony_ci */ 155bebb993Sopenharmony_ci 165bebb993Sopenharmony_ci#include "symlink.h" 175bebb993Sopenharmony_ci#include "file_fs_impl.h" 185bebb993Sopenharmony_ci 195bebb993Sopenharmony_ci#include <cstring> 205bebb993Sopenharmony_ci#include <fcntl.h> 215bebb993Sopenharmony_ci#include <tuple> 225bebb993Sopenharmony_ci#include <unistd.h> 235bebb993Sopenharmony_ci 245bebb993Sopenharmony_cinamespace OHOS { 255bebb993Sopenharmony_cinamespace CJSystemapi { 265bebb993Sopenharmony_ci 275bebb993Sopenharmony_ciusing namespace std; 285bebb993Sopenharmony_ci 295bebb993Sopenharmony_ciint SymlinkImpl::Symlink(const std::string& target, const std::string& srcPath) 305bebb993Sopenharmony_ci{ 315bebb993Sopenharmony_ci LOGI("FS_TEST::SymlinkImpl::Symlink start"); 325bebb993Sopenharmony_ci 335bebb993Sopenharmony_ci std::unique_ptr<uv_fs_t, decltype(CommonFunc::FsReqCleanup)*> symlink_req = { 345bebb993Sopenharmony_ci new (std::nothrow) uv_fs_t, CommonFunc::FsReqCleanup }; 355bebb993Sopenharmony_ci if (!symlink_req) { 365bebb993Sopenharmony_ci LOGE("Failed to request heap memory."); 375bebb993Sopenharmony_ci return ENOMEM; 385bebb993Sopenharmony_ci } 395bebb993Sopenharmony_ci int ret = uv_fs_symlink(nullptr, symlink_req.get(), target.c_str(), srcPath.c_str(), 0, nullptr); 405bebb993Sopenharmony_ci if (ret < 0) { 415bebb993Sopenharmony_ci LOGE("Failed to create a link for old path"); 425bebb993Sopenharmony_ci return ret; 435bebb993Sopenharmony_ci } 445bebb993Sopenharmony_ci 455bebb993Sopenharmony_ci LOGI("FS_TEST::SymlinkImpl::Symlink success"); 465bebb993Sopenharmony_ci return ret; 475bebb993Sopenharmony_ci} 485bebb993Sopenharmony_ci 495bebb993Sopenharmony_ci} // namespace CJSystemapi 505bebb993Sopenharmony_ci} // namespace OHOS 51