Enable parent-to-subdirectory check for rsync-rename moves

Prevents moving a directory into its own subdirectory, which would cause
rsync --backup-dir to create nested structures and fail to delete source.

Example prevented: /mnt/disk1/parent → /mnt/disk1/parent/subfolder

The check uses trailing slashes to ensure exact directory boundary matching
and prevent false positives (e.g., /parent vs /parent2).
This commit is contained in:
mgutt
2025-10-25 15:58:13 +02:00
parent ef0be9c2b7
commit f105f35369

View File

@@ -334,13 +334,13 @@ while (true) {
}
}
// // target must not be a subdirectory of source parent (backup-dir should be outside source tree)
// $source_parent_dir = dirname($valid_source_path);
// if (strpos(rtrim($target,'/'), rtrim($source_parent_dir,'/') . '/') === 0) {
// $reply['error'] = 'Cannot move directory into its own subdirectory';
// $use_rsync_rename = false;
// break 2; // break out of both foreach and if
// }
// target must not be a subdirectory of any source (backup-dir should be outside source tree)
$parent_dir = dirname($valid_source_path);
if (strpos(rtrim($target,'/') . '/', rtrim($parent_dir,'/') . '/') === 0) {
$reply['error'] = 'Cannot move directory into its own subdirectory';
$use_rsync_rename = false;
break 2; // break out of both foreach and if
}
}
}