Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
Signed-off-by: leleliu008 <[email protected]>
  • Loading branch information
leleliu008 committed Nov 14, 2023
1 parent cb5fadb commit 32fe3da
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -2408,9 +2408,7 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta
return PPKG_ERROR_ARG_IS_NULL;
}

size_t dirPathLength = strlen(dirPath);

if (dirPathLength == 0U) {
if (dirPath[0] == '\0') {
return PPKG_ERROR_ARG_IS_EMPTY;
}

Expand All @@ -2421,6 +2419,8 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta
return PPKG_ERROR;
}

size_t dirPathLength = strlen(dirPath);

int ret = PPKG_OK;

struct stat st;
Expand All @@ -2433,7 +2433,7 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta
if (dir_entry == NULL) {
if (errno == 0) {
closedir(dir);
break;
return PPKG_OK;
} else {
perror(dirPath);
closedir(dir);
Expand All @@ -2452,6 +2452,7 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta

if (ret < 0) {
perror(NULL);
closedir(dir);
return PPKG_ERROR;
}

Expand All @@ -2462,7 +2463,13 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta
}

if (S_ISDIR(st.st_mode)) {
fprintf(installedManifestFile, "d|%s/\n", &filePath[offset]);
ret = fprintf(installedManifestFile, "d|%s/\n", &filePath[offset]);

if (ret < 0) {
perror(NULL);
closedir(dir);
return PPKG_ERROR;
}

ret = generate_manifest_r(filePath, offset, installedManifestFile);

Expand All @@ -2471,11 +2478,15 @@ static int generate_manifest_r(const char * dirPath, size_t offset, FILE * insta
return ret;
}
} else {
fprintf(installedManifestFile, "f|%s\n", &filePath[offset]);
ret = fprintf(installedManifestFile, "f|%s\n", &filePath[offset]);

if (ret < 0) {
perror(NULL);
closedir(dir);
return PPKG_ERROR;
}
}
}

return ret;
}

int generate_manifest(const char * installedDIRPath) {
Expand Down

0 comments on commit 32fe3da

Please sign in to comment.