filemanager: Fix deep copying

This commit is contained in:
Johannes Zellner
2021-03-23 14:51:51 +01:00
parent ff5ad8b062
commit 0bd250a34b

View File

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