Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,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);

Expand All @@ -2298,6 +2346,7 @@
oldFile.data('size', newSize);
oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize));
}
self.reload();
})
.fail(function(status) {
if (status === 412) {
Expand Down