From 2d74df47a102dd421743b010e2f5e52b4b4c59d5 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Wed, 10 Mar 2021 13:05:14 +1100 Subject: [PATCH 1/2] Fix IsPathInDir --- pkg/utils/file.go | 2 +- pkg/utils/file_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pkg/utils/file_test.go diff --git a/pkg/utils/file.go b/pkg/utils/file.go index 9e0368db7ce..563c3fa545f 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -276,7 +276,7 @@ func IsPathInDir(dir, pathToCheck string) bool { rel, err := filepath.Rel(dir, pathToCheck) if err == nil { - if !strings.HasPrefix(rel, ".."+string(filepath.Separator)) { + if !strings.HasPrefix(rel, "..") { return true } } diff --git a/pkg/utils/file_test.go b/pkg/utils/file_test.go new file mode 100644 index 00000000000..611ea396490 --- /dev/null +++ b/pkg/utils/file_test.go @@ -0,0 +1,43 @@ +package utils + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsPathInDir(t *testing.T) { + type test struct { + dir string + pathToCheck string + expected bool + } + + const parentDirName = "parentDir" + const subDirName = "subDir" + const filename = "filename" + subDir := filepath.Join(parentDirName, subDirName) + fileInSubDir := filepath.Join(subDir, filename) + fileInParentDir := filepath.Join(parentDirName, filename) + subSubSubDir := filepath.Join(parentDirName, subDirName, subDirName, subDirName) + + tests := []test{ + {dir: parentDirName, pathToCheck: subDir, expected: true}, + {dir: subDir, pathToCheck: subDir, expected: true}, + {dir: subDir, pathToCheck: parentDirName, expected: false}, + {dir: subDir, pathToCheck: fileInSubDir, expected: true}, + {dir: parentDirName, pathToCheck: fileInSubDir, expected: true}, + {dir: subDir, pathToCheck: fileInParentDir, expected: false}, + {dir: parentDirName, pathToCheck: fileInParentDir, expected: true}, + {dir: parentDirName, pathToCheck: filename, expected: false}, + {dir: parentDirName, pathToCheck: subSubSubDir, expected: true}, + {dir: subSubSubDir, pathToCheck: parentDirName, expected: false}, + } + + assert := assert.New(t) + for i, tc := range tests { + result := IsPathInDir(tc.dir, tc.pathToCheck) + assert.Equal(tc.expected, result, "[%d] expected: %t for dir: %s; pathToCheck: %s", i, tc.expected, tc.dir, tc.pathToCheck) + } +} From bf0f740f5c9567d8f8e54e9b89212e0584f05032 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 11 Mar 2021 13:05:44 +1100 Subject: [PATCH 2/2] Add changelog entry --- ui/v2.5/src/components/Changelog/versions/v060.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/v2.5/src/components/Changelog/versions/v060.md b/ui/v2.5/src/components/Changelog/versions/v060.md index 811fae3d3a1..014824f387c 100644 --- a/ui/v2.5/src/components/Changelog/versions/v060.md +++ b/ui/v2.5/src/components/Changelog/versions/v060.md @@ -18,6 +18,7 @@ * Added Rescan button to scene, image, gallery details overflow button. ### 🐛 Bug fixes +* Fix incorrect folders being excluded during scanning. * Filter out streaming resolution options that are over the maximum streaming resolution. * Fix `cover.jpg` not being detected as cover image when in sub-directory. * Fix scan re-associating galleries to the same scene.