diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-22 17:37:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 17:37:04 +0100 |
commit | 68ad2ae11873933ca2212df5a141e49cafa83c33 (patch) | |
tree | f16ff87871386deb208a263254e3b723bedd56d1 /apps | |
parent | 510f720778646499c622c967752c53884e325cb5 (diff) | |
parent | 802e4a79d1d86a3f4ffdd253859c798b16d9ab1c (diff) | |
download | nextcloud-server-68ad2ae11873933ca2212df5a141e49cafa83c33.tar.gz nextcloud-server-68ad2ae11873933ca2212df5a141e49cafa83c33.zip |
Merge pull request #10825 from greenido/fixing-issue-9931
Copy a file to the same directory
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/filelist.js | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 7a8a8b80e10..bcecdb697fe 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2313,7 +2313,55 @@ // not overwrite it targetPath = targetPath + '/'; } - self.filesClient.copy(dir + fileName, targetPath + fileName) + var targetPathAndName = targetPath + fileName; + if ((dir + fileName) === targetPathAndName) { + var dotIndex = targetPathAndName.indexOf("."); + if ( dotIndex > 1) { + var leftPartOfName = targetPathAndName.substr(0, dotIndex); + var fileNumber = leftPartOfName.match(/\d+/); + // TRANSLATORS name that is appended to copied files with the same name, will be put in parenthesis and appened with a number if it is the second+ copy + var copyNameLocalized = t('files', 'copy'); + if (isNaN(fileNumber) ) { + fileNumber++; + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, " (" + copyNameLocalized + " " + fileNumber + ")"); + } + else { + // Check if we have other files with 'copy X' and the same name + var maxNum = 1; + if (self.files !== null) { + leftPartOfName = leftPartOfName.replace("/", ""); + leftPartOfName = leftPartOfName.replace(new RegExp("\\(" + copyNameLocalized + "( \\d+)?\\)"),""); + // find the last file with the number extension and add one to the new name + for (var j = 0; j < self.files.length; j++) { + var cName = self.files[j].name; + if (cName.indexOf(leftPartOfName) > -1) { + if (cName.indexOf("(" + copyNameLocalized + ")") > 0) { + targetPathAndName = targetPathAndName.replace(new RegExp(" \\(" + copyNameLocalized + "\\)"),""); + if (maxNum == 1) { + maxNum = 2; + } + } + else { + var cFileNumber = cName.match(new RegExp("\\(" + copyNameLocalized + " (\\d+)\\)")); + if (cFileNumber && parseInt(cFileNumber[1]) >= maxNum) { + maxNum = parseInt(cFileNumber[1]) + 1; + } + } + } + } + targetPathAndName = targetPathAndName.replace(new RegExp(" \\(" + copyNameLocalized + " \\d+\\)"),""); + } + // Create the new file name with _x at the end + // Start from 2 per a special request of the 'standard' + var extensionName = " (" + copyNameLocalized + " " + maxNum +")"; + if (maxNum == 1) { + extensionName = " (" + copyNameLocalized + ")"; + } + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, extensionName); + } + } + } + self.filesClient.copy(dir + fileName, targetPathAndName) .done(function () { filesToNotify.push(fileName); @@ -2327,6 +2375,7 @@ oldFile.data('size', newSize); oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize)); } + self.reload(); }) .fail(function(status) { if (status === 412) { |