Skip to content

Commit

Permalink
Fix for detecting whether a new location is a parent of an existing l…
Browse files Browse the repository at this point in the history
…ocation, fixes #405
  • Loading branch information
RvanderLaan committed Mar 5, 2022
1 parent 8ff39be commit 53d45cc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/frontend/containers/Outliner/LocationsPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,16 @@ const LocationsPanel = observer(() => {
return;
}

// Check if the new location already exists
const existingDir = locationStore.exists((dir) => path === dir.path);
if (existingDir) {
AppToaster.show({
message: 'This folder has already been added as a location.',
timeout: 5000,
});
return;
}

// Check if the new location is a sub-directory of an existing location
const parentDir = locationStore.exists((dir) => path.includes(dir.path));
if (parentDir) {
Expand All @@ -556,7 +566,11 @@ const LocationsPanel = observer(() => {
}

// Check if the new location is a parent-directory of an existing location
const childDir = locationStore.exists((dir) => dir.path.includes(path));
// Need to add a separator at the end, otherwise the new path /foo is detected as a parent of existing location /football.
// - /foo/ is not a parent directory of /football
// - /foo/ is a parent directory of /foo/bar
const pathWithSeparator = path.endsWith(SysPath.sep) ? path : path + SysPath.sep;
const childDir = locationStore.exists((dir) => dir.path.includes(pathWithSeparator));
if (childDir) {
AppToaster.show({
message: 'You cannot add a location that is a parent-folder of an existing location.',
Expand Down

0 comments on commit 53d45cc

Please sign in to comment.