From 7a16383b4f55b1582d98f01f55d4450ec615d182 Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 28 Mar 2022 19:23:27 +0300 Subject: [PATCH] Fix symlink name on duplicates --- extensions/file-manager/create_symlink.cgi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extensions/file-manager/create_symlink.cgi b/extensions/file-manager/create_symlink.cgi index 97168cffd..52e44bc78 100755 --- a/extensions/file-manager/create_symlink.cgi +++ b/extensions/file-manager/create_symlink.cgi @@ -21,10 +21,20 @@ if (!@entries_list) { foreach my $name (@entries_list) { my $name_ = $name; $name = simplify_path($name); - my $symlink = "$cwd/${name}_symlink"; + my $symlink = "$cwd/${name}--symlink"; + + # If symlink exists add a numerable suffix if (-e $symlink) { - $symlink .= "_" . int(rand() * 10000); + my $__ = 1; + for (;;) { + my $necwd = "$symlink(" . $__++ . ")"; + if (!-e $necwd) { + $symlink = $necwd; + last; + } + } } + if (symlink_file("$cwd/$name", $symlink) == 0) { $error .= "
" if ($error); $error .= text('filemanager_symlink_exists', html_escape("${name_}_symlink"), html_escape($cwd));