From 7fe7c7835e7cfe438c30caaac5f7c98b3bc99256 Mon Sep 17 00:00:00 2001 From: shilei Date: Thu, 22 Sep 2022 17:06:41 +0800 Subject: [PATCH] fix problem Signed-off-by: shilei Change-Id: I33a5796e112a6595c6836134c2e182c81e93fd19 --- .../bundle_daemon/include/bundle_file_utils.h | 1 + .../bundle_daemon/src/bundle_daemon.cpp | 2 +- .../src/bundle_daemon_handler.cpp | 4 +-- .../bundle_daemon/src/bundle_file_utils.cpp | 26 +++++++++++++++++++ .../src/bundle_daemon_client.cpp | 2 +- .../src/gt_bundle_extractor.cpp | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h b/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h index 1e62034..738943d 100644 --- a/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h +++ b/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h @@ -29,6 +29,7 @@ const char PATH_SEPARATOR = '/'; class BundleFileUtils : public NoCopyable { public: static bool MkRecursiveDir(const char *dir, bool isReadOthers); + static bool MkOwnerDir(const char *dir); static bool IsExistDir(const char *path); static bool IsExistFile(const char *file); static bool RemoveFile(const char *path); diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp index 3d4c436..419c89a 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp @@ -211,7 +211,7 @@ int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req) int32_t uid = IpcIoPopInt32(req); int32_t gid = IpcIoPopInt32(req); bool isChown = IpcIoPopBool(req); - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown); } diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp index 0afce61..788b1c5 100755 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp @@ -140,12 +140,12 @@ int32_t BundleDaemonHandler::CreateDataDirectory(const char *dataPath, int32_t u } if (!BundleFileUtils::IsExistDir(dataDir.c_str())) { - if (!BundleFileUtils::MkRecursiveDir(dataDir.c_str(), false)) { + if (!BundleFileUtils::MkOwnerDir(dataDir.c_str())) { PRINTE("BundleDaemonHandler", "create dataPath fail"); return EC_NODIR; } } - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); if (isChown && !BundleFileUtils::ChownFile(dataDir.c_str(), uid, gid)) { PRINTE("BundleDaemonHandler", "chown file fail"); return EC_NOFILE; diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp index 6422d04..ab1debc 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp @@ -78,6 +78,32 @@ bool BundleFileUtils::MkRecursiveDir(const char *dir, bool isReadOthers) return true; } +bool BundleFileUtils::MkOwnerDir(const char *dir) +{ + if (dir == nullptr) { + return false; + } + if (IsExistDir(dir)) { + return true; + } + size_t len = strlen(dir); + if (len == 0 || len > PATH_MAX) { + return false; + } + // Create directories level by level + char rootDir[PATH_MAX] = { '\0' }; + for (size_t i = 0; i < len; ++i) { + rootDir[i] = dir[i]; + if ((rootDir[i] == PATH_SEPARATOR || i == (len - 1)) && !IsExistDir(rootDir)) { + mode_t mode = S_IRWXU | S_IRWXG; + if (mkdir(rootDir, mode) < 0) { + return false; + } + } + } + return true; +} + bool BundleFileUtils::RemoveFile(const char *path) { if (IsExistFile(path)) { diff --git a/services/bundlemgr_lite/src/bundle_daemon_client.cpp b/services/bundlemgr_lite/src/bundle_daemon_client.cpp index b2367a0..e9529fc 100755 --- a/services/bundlemgr_lite/src/bundle_daemon_client.cpp +++ b/services/bundlemgr_lite/src/bundle_daemon_client.cpp @@ -302,7 +302,7 @@ int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t ui IpcIoPushInt32(&request, uid); IpcIoPushInt32(&request, gid); IpcIoPushBool(&request, isChown); - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); Lock lock(mutex_); #ifdef __LINUX__ return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, this, Notify)); diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 5a3f6eb..cfc0de1 100755 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -154,7 +154,7 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32 } int32_t fileNameLen = strlen(fileName); - if ((strlen(relativeFilePath) == 0 && (fileName != nullptr && strcmp(fileName, PROFILE_NAME) == 0)) || + if ((strlen(relativeFilePath) == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) || !BundleUtil::StartWith(relativeFilePath, ASSET_JS_PATH)) { if (!GtExtractorUtil::HasWrittenFile(path, relativeFilePath, fileName, fp, fileSize)) { UI_Free(fileName); -- Gitee