Browse Source

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>
tags/v16.0.0alpha1
Ido Green 5 years ago
parent
commit
c794452689
No account linked to committer's email address
3 changed files with 40 additions and 1 deletions
  1. 1
    0
      .gitignore
  2. 4
    0
      .htaccess
  3. 35
    1
      apps/files/js/filelist.js

+ 1
- 0
.gitignore View File

@@ -150,3 +150,4 @@ clover.xml
# Tests - dependencies
tests/acceptance/composer.lock
tests/acceptance/vendor/


+ 4
- 0
.htaccess View File

@@ -80,3 +80,7 @@ Options -Indexes
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 //
ErrorDocument 404 //

+ 35
- 1
apps/files/js/filelist.js View File

@@ -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) {

Loading…
Cancel
Save