diff options
author | Ido Green <igreen@netflix.com> | 2018-08-23 10:23:41 -0700 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-11-19 13:56:40 +0100 |
commit | c794452689d2a26d3922f995eb694c6b444fccb1 (patch) | |
tree | 678915dfc6083f546d7881ecd47745917ddf17fe | |
parent | ea46c111a0b0352fc5e7ec67de25f64bcc30def0 (diff) | |
download | nextcloud-server-c794452689d2a26d3922f995eb694c6b444fccb1.tar.gz nextcloud-server-c794452689d2a26d3922f995eb694c6b444fccb1.zip |
fixing issue 9931 - copy a file to the same directory
Signed-off-by: Ido Green <greenido@gmail.com>
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .htaccess | 4 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 36 |
3 files changed, 40 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index cad26d1a88d..229eb172b1a 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,4 @@ clover.xml # Tests - dependencies tests/acceptance/composer.lock tests/acceptance/vendor/ + diff --git a/.htaccess b/.htaccess index 63d50a2b9d7..aa16193ec9c 100644 --- a/.htaccess +++ b/.htaccess @@ -80,3 +80,7 @@ Options -Indexes <IfModule pagespeed_module> ModPagespeed Off </IfModule> +#### DO NOT CHANGE ANYTHING ABOVE THIS LINE #### + +ErrorDocument 403 // +ErrorDocument 404 // diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 94fdada937d..7467cf002f2 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2284,7 +2284,40 @@ // not overwrite it targetPath = targetPath + '/'; } - self.filesClient.copy(dir + fileName, targetPath + fileName) + let targetPathAndName = targetPath + fileName; + if ((dir + fileName) === targetPathAndName) { + let dotIndex = targetPathAndName.indexOf("."); + if ( dotIndex > 1) { + let leftPartOfName = targetPathAndName.substr(0, dotIndex); + let fileNumber = leftPartOfName.match(/\d+/); + if (isNaN(fileNumber) ) { + fileNumber++; + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, "_" + fileNumber); + } + else { + // check if we have other files with _x and the same name + let maxNum = 1; + if (self.files !== null) { + leftPartOfName = leftPartOfName.replace("/", ""); + leftPartOfName = leftPartOfName.replace(/_\d+/,""); + // find the last file with the number extention and add one to the new name + for (let j = 0; j < self.files.length; j++) { + const cName = self.files[j].name; + if (cName.indexOf(leftPartOfName) > -1) { + let cFileNumber = cName.match(/_(\d+)/); + if (cFileNumber && parseInt(cFileNumber[1]) >= maxNum) { + maxNum = parseInt(cFileNumber[1]) + 1; + } + } + } + targetPathAndName = targetPathAndName.replace(/_\d+/,""); + } + // Create the new file name with _x at the end + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, "_" + maxNum); + } + } + } + self.filesClient.copy(dir + fileName, targetPathAndName) .done(function () { filesToNotify.push(fileName); @@ -2298,6 +2331,7 @@ oldFile.data('size', newSize); oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize)); } + self.reload(); }) .fail(function(status) { if (status === 412) { |