In src/shared/utils.c:84-121, the delete_extras_walk function has a bug in directory handling:
staticvoiddelete_extras_walk(constchar*abs_path,constchar*rel_path,ArrayList*manifest){DIR*dir=opendir(abs_path);if(!dir)return;structdirent*entry;while((entry=readdir(dir))!=NULL){// ... handles files and subdirectories recursively
}closedir(dir);rmdir(abs_path);// BUG: Always called, even for non-empty directories
}
The rmdir(abs_path) at the end is called unconditionally for every directory, including:
The root destination directory itself -- which means if --delete is used, an attempt will be made to remove the root destination directory (which will likely fail with ENOTEMPTY since manifest files should remain)
Any directory that still has files in the manifest -- rmdir will fail silently
If the directory still contains files (matched by manifest), rmdir will fail with ENOTEMPTY but the error is not checked. This is likely the intended behavior (failing silently for directories with preserved files), but it should at least log a debug message.
More critically, the root destination directory is always passed to rmdir after processing, which will always fail (since it contains preserved files).
Fix: Only call rmdir if the directory no longer contains any files after deletion processing, or at minimum check the return value.
Severity: medium
In src/shared/utils.c:84-121, the delete_extras_walk function has a bug in directory handling:
```c
static void delete_extras_walk(const char* abs_path, const char* rel_path, ArrayList* manifest) {
DIR* dir = opendir(abs_path);
if (!dir) return;
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
// ... handles files and subdirectories recursively
}
closedir(dir);
rmdir(abs_path); // BUG: Always called, even for non-empty directories
}
```
The `rmdir(abs_path)` at the end is called unconditionally for every directory, including:
1. The root destination directory itself -- which means if --delete is used, an attempt will be made to remove the root destination directory (which will likely fail with ENOTEMPTY since manifest files should remain)
2. Any directory that still has files in the manifest -- rmdir will fail silently
If the directory still contains files (matched by manifest), rmdir will fail with ENOTEMPTY but the error is not checked. This is likely the intended behavior (failing silently for directories with preserved files), but it should at least log a debug message.
More critically, the root destination directory is always passed to rmdir after processing, which will always fail (since it contains preserved files).
Fix: Only call rmdir if the directory no longer contains any files after deletion processing, or at minimum check the return value.
Severity: medium
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
In src/shared/utils.c:84-121, the delete_extras_walk function has a bug in directory handling:
The
rmdir(abs_path)at the end is called unconditionally for every directory, including:If the directory still contains files (matched by manifest), rmdir will fail with ENOTEMPTY but the error is not checked. This is likely the intended behavior (failing silently for directories with preserved files), but it should at least log a debug message.
More critically, the root destination directory is always passed to rmdir after processing, which will always fail (since it contains preserved files).
Fix: Only call rmdir if the directory no longer contains any files after deletion processing, or at minimum check the return value.
Severity: medium