Skip to content

Commit 5ff5295

Browse files
committed
fix: clean up empty directory after payload deletion
fixes issue #24
1 parent bfc4d09 commit 5ff5295

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/payload_mgr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ static int is_allowed_usb_path(const char *path) {
10181018
int payload_mgr_delete_payload_file(const char *filename) {
10191019
char path[512];
10201020
char details_path[640];
1021+
char dir_path[512];
1022+
char *last_slash;
10211023

10221024
if (!filename || strstr(filename, "/") || strstr(filename, "..")) {
10231025
return -1;
@@ -1037,6 +1039,15 @@ static int is_allowed_usb_path(const char *path) {
10371039
/* Remove from autoload.txt if present */
10381040
pldmgr_autoload_update_config_entry(filename, NULL);
10391041

1042+
/* Try to remove the containing directory (will fail if not empty) */
1043+
strncpy(dir_path, path, sizeof(dir_path));
1044+
dir_path[sizeof(dir_path) - 1] = '\0';
1045+
last_slash = strrchr(dir_path, '/');
1046+
if (last_slash) {
1047+
*last_slash = '\0';
1048+
rmdir(dir_path);
1049+
}
1050+
10401051
return 0;
10411052
}
10421053

0 commit comments

Comments
 (0)