summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorIdo Green <igreen@netflix.com>2018-08-23 10:23:41 -0700
committerMorris Jobke <hey@morrisjobke.de>2018-11-19 13:56:40 +0100
commitc794452689d2a26d3922f995eb694c6b444fccb1 (patch)
tree678915dfc6083f546d7881ecd47745917ddf17fe /apps/files
parentea46c111a0b0352fc5e7ec67de25f64bcc30def0 (diff)
downloadnextcloud-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>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/js/filelist.js36
1 files changed, 35 insertions, 1 deletions
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) {