Skip to content

Commit

Permalink
modified directory-scanning to short-circuit if match found
Browse files Browse the repository at this point in the history
  • Loading branch information
Fortier authored and Fortier committed Jan 16, 2018
1 parent 605212f commit d4ff6d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,15 @@ angular.module('documents')
return Promise.reject('Destination required for moving files and folders.');
} else {
//Check destination directory for folders of identical name to selected folder(s).
var repeat = false;
destination.children.forEach(function(destFolder) {
self.moveSelected.moveableFolders.forEach(function(srcFolder) {
if (destFolder.model.name === srcFolder.model.name) {
repeat = true;
AlertService.error('Folder name ' + destFolder.model.name + ' already exists in ' + destination.model.name);
}

var repeat = _.find(self.moveSelected.moveableFolders, function(srcFolder) {
return _.find(destination.children, function(destFolder) {
return destFolder.model.name === srcFolder.model.name;
});
});
if (!repeat) {
//If repeat name found, throw error. Otherwise, continue with move.
if (repeat) {
AlertService.error('Folder name ' + repeat.model.name + ' already exists in ' + destination.model.name);
} else {
var dirs = _.size(self.checkedDirs);
var files = _.size(self.checkedFiles);
if (dirs === 0 && files === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ angular.module('documents')

self.ok = function () {
//Check if there is already a folder of name ${entryText} in current directory.
var repeat = false;
$scope.node.parent.children.forEach(function(element) {
if (self.entryText === element.model.name) {
repeat = true;
AlertService.error(self.entryText + " already exists in this directory.");
}
var repeat = _.find($scope.node.parent.children, function(element) {
return element.model.name === self.entryText;
});
//If ${entryText} is a unique name for this directory, rename the folder.
if (!repeat) {
//If ${entryText} is a unique name for this directory, rename the folder, otherwise throw an error.
if (repeat) {
AlertService.error(self.entryText + " already exists in this directory.");
} else {
DocumentMgrService.renameDirectory($scope.project, $scope.node, self.entryText)
.then(
function (result) {
Expand Down

0 comments on commit d4ff6d1

Please sign in to comment.