mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2025-02-17 06:28:19 +00:00
!7345 清除data数据时,包目录下的软链接无法清除
Merge pull request !7345 from small_leek/addselinux
This commit is contained in:
commit
c4799fd2e8
@ -37,6 +37,12 @@ using EnforceMetadataProcessForApp = int32_t (*)(const std::unordered_map<std::s
|
||||
|
||||
class InstalldOperator {
|
||||
public:
|
||||
/**
|
||||
* @brief Check link file and unlink.
|
||||
* @param path Indicates the file path to be checked.
|
||||
* @return Returns true if the file is link and unlink succeed; returns false otherwise.
|
||||
*/
|
||||
static bool CheckAndDeleteLinkFile(const std::string &path);
|
||||
/**
|
||||
* @brief Check whether a file exist.
|
||||
* @param path Indicates the file path to be checked.
|
||||
|
@ -138,6 +138,23 @@ struct fscrypt_asdp_policy {
|
||||
char app_key2_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
bool InstalldOperator::CheckAndDeleteLinkFile(const std::string &path)
|
||||
{
|
||||
struct stat path_stat;
|
||||
if (lstat(path.c_str(), &path_stat) == 0) {
|
||||
if (S_ISLNK(path_stat.st_mode)) {
|
||||
if (unlink(path.c_str()) == 0) {
|
||||
return true;
|
||||
}
|
||||
LOG_E(BMS_TAG_INSTALLD, "CheckAndDeleteLinkFile unlink %{public}s failed, error: %{public}d",
|
||||
path.c_str(), errno);
|
||||
}
|
||||
}
|
||||
LOG_E(BMS_TAG_INSTALLD, "CheckAndDeleteLinkFile lstat or S_ISLNK %{public}s failed, errno:%{public}d",
|
||||
path.c_str(), errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstalldOperator::IsExistFile(const std::string &path)
|
||||
{
|
||||
if (path.empty()) {
|
||||
@ -770,12 +787,20 @@ bool InstalldOperator::DeleteFiles(const std::string &dataPath)
|
||||
}
|
||||
subPath = OHOS::IncludeTrailingPathDelimiter(dataPath) + std::string(ptr->d_name);
|
||||
if (ptr->d_type == DT_DIR) {
|
||||
ret = OHOS::ForceRemoveDirectory(subPath);
|
||||
} else {
|
||||
if (access(subPath.c_str(), F_OK) == 0) {
|
||||
ret = OHOS::RemoveFile(subPath);
|
||||
if (!OHOS::ForceRemoveDirectory(subPath)) {
|
||||
ret = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (access(subPath.c_str(), F_OK) == 0) {
|
||||
ret = OHOS::RemoveFile(subPath);
|
||||
if (!ret) {
|
||||
LOG_I(BMS_TAG_INSTALLD, "RemoveFile %{public}s failed, error: %{public}d", subPath.c_str(), errno);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// maybe lnk_file
|
||||
ret = CheckAndDeleteLinkFile(subPath);
|
||||
}
|
||||
closedir(dir);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user