Skip to content

Commit 4c2f115

Browse files
committed
Inline CreateParentDirectories into ExportFile and remove helper
- Remove CreateParentDirectories helper function (only used by ExportFile) - Inline its directory-creation logic directly within ExportFile - Simplify code by eliminating unnecessary indirection
1 parent 19aec3d commit 4c2f115

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/filesystem_utils.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,26 +274,6 @@ bool CreateDirectoriesRecursively(const char *dir)
274274
return result;
275275
}
276276

277-
// Creates all necessary parent directories for a given file path.
278-
bool CreateParentDirectories(const char *file)
279-
{
280-
if (file == NULL || *file == '\0') {
281-
APP_ERROR("file is null or empty");
282-
return false;
283-
}
284-
285-
char *dir = GetParentPath(file);
286-
if (!dir) {
287-
APP_ERROR("Failed to get parent path");
288-
return false;
289-
}
290-
291-
bool result = CreateDirectoriesRecursively(dir);
292-
293-
free(dir);
294-
return result;
295-
}
296-
297277
// Deletes a directory and all its contents recursively.
298278
bool DeleteRecursively(const char *path)
299279
{
@@ -533,6 +513,7 @@ bool ChangeDirectoryToSafeDirectory(void)
533513
bool ExportFile(const char *path, const void *buffer, size_t buffer_size)
534514
{
535515
bool result = false;
516+
char *parent = NULL;
536517
HANDLE hFile = INVALID_HANDLE_VALUE;
537518
DWORD written = 0;
538519

@@ -545,7 +526,14 @@ bool ExportFile(const char *path, const void *buffer, size_t buffer_size)
545526
goto cleanup;
546527
}
547528

548-
if (!CreateParentDirectories(path)) {
529+
parent = GetParentPath(path);
530+
if (!parent) {
531+
APP_ERROR("Failed to get parent path");
532+
533+
goto cleanup;
534+
}
535+
536+
if (!CreateDirectoriesRecursively(parent)) {
549537
APP_ERROR("ExportFile: Failed to create parent directory for %s", path);
550538

551539
goto cleanup;
@@ -586,6 +574,9 @@ bool ExportFile(const char *path, const void *buffer, size_t buffer_size)
586574
result = true;
587575

588576
cleanup:
577+
if (parent) {
578+
free(parent);
579+
}
589580
if (hFile != INVALID_HANDLE_VALUE) {
590581
CloseHandle(hFile);
591582
}

src/filesystem_utils.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ char *GetParentPath(const char *path);
6262
*/
6363
bool CreateDirectoriesRecursively(const char *dir);
6464

65-
/**
66-
* CreateParentDirectories - Creates all parent directories of the specified file path.
67-
*
68-
* @param file The path of the file whose parent directories need to be created.
69-
* @return true if the parent directories were successfully created or already exist.
70-
* false if the directories could not be created due to an error.
71-
*/
72-
bool CreateParentDirectories(const char *file);
73-
7465
/**
7566
* DeleteRecursively - Deletes a directory and all its contents recursively.
7667
*

0 commit comments

Comments
 (0)