gui: Improve warnings when creating folder in a subdirectory (fixes #3197, fixes #3902)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3904
This commit is contained in:
KAMADA Ken'ichi
2017-01-14 12:18:48 +00:00
committed by Audrius Butkevicius
parent c953cdc375
commit 929a4d0c0c
3 changed files with 18 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ angular.module('syncthing.core')
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue) {
// This function checks whether xdir is a subdirectory of ydir,
// This function checks whether ydir is a subdirectory of xdir,
// e.g. it would return true if xdir = "/home/a", ydir = "/home/a/b".
function isSubDir(xdir, ydir) {
var xdirArr = xdir.split(scope.system.pathSeparator);
@@ -21,13 +21,23 @@ angular.module('syncthing.core')
}
scope.pathIsSubFolder = false;
scope.pathIsParentFolder = false;
scope.otherFolder = "";
scope.otherFolderLabel = "";
for (var folderID in scope.folders) {
if (isSubDir(scope.folders[folderID].path, viewValue)) {
scope.otherFolder = folderID;
scope.otherFolderLabel = scope.folders[folderID].label;
scope.pathIsSubFolder = true;
break;
}
if (viewValue !== "" &&
isSubDir(viewValue, scope.folders[folderID].path)) {
scope.otherFolder = folderID;
scope.otherFolderLabel = scope.folders[folderID].label;
scope.pathIsParentFolder = true;
break;
}
}
return viewValue;
});