mirror of
https://github.com/nextcloud/server.git
synced 2026-04-24 15:53:36 -04:00
Merge pull request #10825 from greenido/fixing-issue-9931
Copy a file to the same directory
This commit is contained in:
commit
68ad2ae118
1 changed files with 50 additions and 1 deletions
|
|
@ -2313,7 +2313,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);
|
||||
|
||||
|
|
@ -2327,6 +2375,7 @@
|
|||
oldFile.data('size', newSize);
|
||||
oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize));
|
||||
}
|
||||
self.reload();
|
||||
})
|
||||
.fail(function(status) {
|
||||
if (status === 412) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue