1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_FILEMGMT_BACKUP_B_GUARD_CWD_H 17 #define OHOS_FILEMGMT_BACKUP_B_GUARD_CWD_H 18 19 /** 20 * @file b_cwd_guard.h 21 * @brief 异常安全的临时变更目录方法 22 * 23 */ 24 25 #include <string_view> 26 27 #include "nocopyable.h" 28 29 namespace OHOS::FileManagement::Backup { 30 class BGuardCwd final : protected NoCopyable { 31 public: 32 /** 33 * @brief 构造器,其中会把当前目录变更为目标目录 34 * 35 * @param tgtDir 目标目录 36 */ 37 explicit BGuardCwd(std::string_view tgtDir); 38 39 /** 40 * @brief 析构器,其中会把目标目录恢复为当前目录 41 * 42 */ 43 ~BGuardCwd() final; 44 45 private: 46 BGuardCwd() = delete; 47 char *pwd_ {nullptr}; 48 }; 49 } // namespace OHOS::FileManagement::Backup 50 51 #endif // OHOS_FILEMGMT_BACKUP_B_GUARD_CWD_H