diff --git a/src/js/filemanager.js b/src/js/filemanager.js index 3226f87a5..d52027e39 100644 --- a/src/js/filemanager.js +++ b/src/js/filemanager.js @@ -440,11 +440,14 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl $scope.clipboard = $scope.selected.slice(); $scope.clipboard.forEach(function (entry) { entry.fullFilePath = sanitize($scope.cwd + '/' + entry.fileName); + entry.pathFrom = $scope.cwd; // we stash the original path for pasting }); $scope.clipboardCut = false; }; function collectFiles(entry, callback) { + var pathFrom = entry.pathFrom; + if (entry.isDirectory) { Client.filesGet($scope.id, $scope.type, entry.fullFilePath, 'data', function (error, result) { if (error) return callback(error); @@ -453,6 +456,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl // amend fullFilePath result.entries.forEach(function (e) { e.fullFilePath = sanitize(entry.fullFilePath + '/' + e.fileName); + e.pathFrom = pathFrom; // we stash the original path for pasting }); var collectedFiles = []; @@ -510,10 +514,11 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl if (error) return Client.error(error); async.eachLimit(collectedFiles, 5, function (entry, callback) { - var newFilePath = sanitize($scope.cwd + '/' + ((destinationEntry && destinationEntry.isDirectory) ? destinationEntry.fileName : '') + '/' + entry.fullFilePath); + var newFilePath = sanitize($scope.cwd + '/' + ((destinationEntry && destinationEntry.isDirectory) ? destinationEntry.fileName : '') + '/' + entry.fullFilePath.slice(entry.pathFrom.length)); // This will NOT overwrite but finds a unique new name to copy to - Client.filesCopy($scope.id, $scope.type, entry.fullFilePath, newFilePath, callback); + // we prefix with a / to ensure we don't do relative target paths + Client.filesCopy($scope.id, $scope.type, entry.fullFilePath, '/' + newFilePath, callback); }, function (error) { if (error) return Client.error(error);