You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--backup does not keep empty directories in --backup-dir #842
I wonder if that commit was trying to fix another bug that exists in at least 3.1.0, and possibly other versions. When an empty directory is deleted from source but exists in target, and the --delete option is enabled, the empty directory is not placed in --backup-dir. Going to see if I can figure out what exactly the commit changed.
But it seems nobody fixed this or opened an issue for that.
I traced the issue to delete_item() in delete.c where directories are routed directly to do_rmdir() without backup logic. I believe a minimal fix is to mirror the file backup check for S_ISDIR, attempting a rename into --backup-dir before deletion. I can put together a patch and tests if this approach sounds acceptable.
I looked through the current delete/backup path and the behaviour matches the code as delete_item() routes directories directly to do_rmdir_at() while the make_backup() path is only used for non-directories.
One caution for a fix, simply calling make_backup() for every directory delete looks risky. With --backup-dir, child files can already have created backup_dir/sub/...; later trying to back up the parent directory sub/ itself would collide with that existing backup directory. If the collision handling deletes the backup target first it could remove the child backups that were just preserved.
So the safe shape probably needs to be narrower, e.g. backing up a deleted directory only when the backup destination for that directory does not already exist, or otherwise preserving existing backup-dir contents and just removing the now-empty source directory.
Happy to work on this if that direction sounds right to either of you @mgutt / @x15sr71
@steadytao your collision analysis was spot on - the fix handles exactly that case by falling through to rmdir() when the backup destination already exists from child file backups. Opened a PR at #967 that incorporates that approach. Would appreciate your review if you have time.
Activity
x15sr71 commentedon Jan 21, 2026
I traced the issue to
delete_item()indelete.cwhere directories are routed directly todo_rmdir()without backup logic. I believe a minimal fix is to mirror the file backup check forS_ISDIR, attempting a rename into--backup-dirbefore deletion. I can put together a patch and tests if this approach sounds acceptable.steadytao commentedon Jun 3, 2026
I looked through the current delete/backup path and the behaviour matches the code as
delete_item()routes directories directly todo_rmdir_at()while themake_backup()path is only used for non-directories.One caution for a fix, simply calling
make_backup()for every directory delete looks risky. With--backup-dir, child files can already have createdbackup_dir/sub/...; later trying to back up the parent directorysub/itself would collide with that existing backup directory. If the collision handling deletes the backup target first it could remove the child backups that were just preserved.So the safe shape probably needs to be narrower, e.g. backing up a deleted directory only when the backup destination for that directory does not already exist, or otherwise preserving existing backup-dir contents and just removing the now-empty source directory.
Happy to work on this if that direction sounds right to either of you @mgutt / @x15sr71
x15sr71 commentedon Jun 5, 2026
@steadytao your collision analysis was spot on - the fix handles exactly that case by falling through to
rmdir()when the backup destination already exists from child file backups. Opened a PR at #967 that incorporates that approach. Would appreciate your review if you have time.