mirror of
https://github.com/openharmony/bundlemanager_bundle_framework_lite.git
synced 2026-07-19 12:13:04 -04:00
fix problem
Signed-off-by: shilei <shilei91@huawei.com> Change-Id: I33a5796e112a6595c6836134c2e182c81e93fd19
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -200,7 +200,7 @@ int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req)
|
||||
ReadInt32(req, &gid);
|
||||
bool isChown;
|
||||
ReadBool(req, &isChown);
|
||||
|
||||
PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown);
|
||||
return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -283,7 +283,7 @@ int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t ui
|
||||
WriteInt32(&request, uid);
|
||||
WriteInt32(&request, gid);
|
||||
WriteBool(&request, isChown);
|
||||
|
||||
PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown);
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, this, Notify));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user