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>
This commit is contained in:
Ido Green 2018-08-23 10:23:41 -07:00 committed by Morris Jobke
parent ea46c111a0
commit c794452689
No known key found for this signature in database
GPG key ID: FE03C3A163FEDE68
3 changed files with 40 additions and 1 deletions

1
.gitignore vendored
View file

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

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 //

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