From f105f35369a489ea5c7faaf262aa4099b32cede8 Mon Sep 17 00:00:00 2001 From: mgutt <10757176+mgutt@users.noreply.github.com> Date: Sat, 25 Oct 2025 15:58:13 +0200 Subject: [PATCH] Enable parent-to-subdirectory check for rsync-rename moves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- emhttp/plugins/dynamix/nchan/file_manager | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/emhttp/plugins/dynamix/nchan/file_manager b/emhttp/plugins/dynamix/nchan/file_manager index 76bdd8fe4..0dae28f39 100755 --- a/emhttp/plugins/dynamix/nchan/file_manager +++ b/emhttp/plugins/dynamix/nchan/file_manager @@ -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 + } } }