diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 9469f3df535febe5cb6a37fc07e3cae59b09d4fc..d0cbc4b7422738cb288852d26cae3fafedebb012 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -16,6 +16,7 @@ #ifndef OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H #define OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H +#include #include #include @@ -80,6 +81,7 @@ private: void AsyncTaskRestore(); private: + std::shared_mutex lock_; std::shared_ptr extension_; std::vector tars_; OHOS::ThreadPool threadPool_; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 3bb40c76963c0765c6c7110d685327254b3a0504..6cea0bd311034a88726906562bc705ac480ea183 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -108,7 +108,7 @@ ErrCode BackupExtExtension::HandleClear() if (!ForceRemoveDirectory(restoreCache)) { HILOGI("Failed to delete the restore cache %{public}s", restoreCache.c_str()); } - + unique_lock lock(lock_); tars_.clear(); } catch (const BError &e) { return e.GetCode(); @@ -193,10 +193,13 @@ ErrCode BackupExtExtension::PublishFile(const string &fileName) string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); string tarName = path + fileName; - if (find(tars_.begin(), tars_.end(), fileName) != tars_.end() || access(tarName.data(), F_OK) != 0) { - return BError(-EPERM); + { + unique_lock lock(lock_); + if (find(tars_.begin(), tars_.end(), fileName) != tars_.end() || access(tarName.data(), F_OK) != 0) { + return BError(-EPERM); + } + tars_.push_back(fileName); } - tars_.push_back(fileName); // 异步执行解压操作 if (extension_->AllowToBackupRestore()) {