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 1e620342f26a98f253602484a3448e851733a5dc..738943db0c0c95f2d46d1bb68360198e7cf1f565 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 3d4c436ad283952d9ac83a7bb84fae726a157c66..419c89a3dceb5be1a26320d7491d4fd312f6914b 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 0afce614d5fbf34303796d9c875114e4850b1c36..788b1c54d67e4e8b4afccc77b48019128115dbdb 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 6422d04001ff54118f3bd9e48ac1530a627a156a..ab1debc32064e86e939e04a8994d2fd80aae3be8 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 b2367a075d3b1938180e1c13f97c9e34a6559277..e9529fcabed7c8f2db090ffc6758e779453cfcfa 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 5a3f6eb19b891a4f23e6b172c6da907504c5e518..cfc0de1ee8b5b743ed7a5b2df0c88ee7d6f67630 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);