From 842a3fa0bb8fabd5ff3b9a38c9056549d4c5eed4 Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:21:37 +0100 Subject: [PATCH 1/5] fix comments --- list.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/list.go b/list.go index 8d8d6d2..7892fa0 100644 --- a/list.go +++ b/list.go @@ -101,7 +101,7 @@ func (p *PathList) filter(filter func(*Path) bool) { *p = res } -// FilterOutPrefix remove all entries having the specified prefixes +// FilterOutPrefix remove all entries having one of the specified prefixes func (p *PathList) FilterOutPrefix(prefixes ...string) { filterFunction := func(path *Path) bool { return !path.HasPrefix(prefixes...) @@ -117,7 +117,7 @@ func (p *PathList) FilterPrefix(prefixes ...string) { p.filter(filterFunction) } -// FilterOutSuffix remove all entries having the specified suffix +// FilterOutSuffix remove all entries having one of the specified suffixes func (p *PathList) FilterOutSuffix(suffixies ...string) { filterFunction := func(path *Path) bool { return !path.HasSuffix(suffixies...) @@ -125,7 +125,7 @@ func (p *PathList) FilterOutSuffix(suffixies ...string) { p.filter(filterFunction) } -// FilterSuffix remove all entries not having the specified prefix +// FilterSuffix remove all entries not having one of the specified suffixes func (p *PathList) FilterSuffix(suffixies ...string) { filterFunction := func(path *Path) bool { return path.HasSuffix(suffixies...) From 1225ced90890e92104d54425d49dd9d0cd5fd66e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 14 Dec 2022 09:40:41 +0100 Subject: [PATCH 2/5] Removed windows-2016 runner from CI It is no more available: https://github.blog/changelog/2021-10-19-github-actions-the-windows-2016-runner-image-will-be-removed-from-github-hosted-runners-on-march-15-2022/ --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 655508a..a775d8a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,6 @@ jobs: ubuntu-latest, ubuntu-18.04, windows-latest, - windows-2016, macos-latest, ] From e20bcd0b290230b79abe9a1f319490859d382ca7 Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Tue, 11 Apr 2023 10:31:29 +0200 Subject: [PATCH 3/5] Removed ubuntu-18.04 runner from CI Has been deprecated https://github.com/actions/runner-images/issues/6002 --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a775d8a..3eeaec8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,6 @@ jobs: operating-system: [ ubuntu-latest, - ubuntu-18.04, windows-latest, macos-latest, ] From 8780dcc04d13e4329f12387facbc34ec2bdff962 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 28 Apr 2023 16:52:03 +0200 Subject: [PATCH 4/5] Fixed IsInsideDir for paths on different filesystems --- paths.go | 5 ++++- paths_test.go | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/paths.go b/paths.go index b969606..52c036c 100644 --- a/paths.go +++ b/paths.go @@ -191,7 +191,10 @@ func (p *Path) Clean() *Path { func (p *Path) IsInsideDir(dir *Path) (bool, error) { rel, err := filepath.Rel(dir.path, p.path) if err != nil { - return false, err + // If the dir cannot be made relative to this path it means + // that it belong to a different filesystems, so it cannot be + // inside this path. + return false, nil } return !strings.Contains(rel, ".."+string(os.PathSeparator)) && rel != ".." && rel != ".", nil } diff --git a/paths_test.go b/paths_test.go index 4e7817a..6b5f236 100644 --- a/paths_test.go +++ b/paths_test.go @@ -154,16 +154,17 @@ func TestResetStatCacheWhenFollowingSymlink(t *testing.T) { } func TestIsInsideDir(t *testing.T) { - inside := func(a, b *Path) { + notInside := func(a, b *Path) { in, err := a.IsInsideDir(b) require.NoError(t, err) - require.True(t, in, "%s is inside %s", a, b) + require.False(t, in, "%s is inside %s", a, b) } - notInside := func(a, b *Path) { + inside := func(a, b *Path) { in, err := a.IsInsideDir(b) require.NoError(t, err) - require.False(t, in, "%s is inside %s", a, b) + require.True(t, in, "%s is inside %s", a, b) + notInside(b, a) } f1 := New("/a/b/c") @@ -196,6 +197,14 @@ func TestIsInsideDir(t *testing.T) { f5 := New("/home/megabug/a15/packages") notInside(f5, f4) notInside(f4, f5) + + if runtime.GOOS == "windows" { + f6 := New("C:\\", "A") + f7 := New("C:\\", "A", "B", "C") + f8 := New("E:\\", "A", "B", "C") + inside(f7, f6) + notInside(f8, f6) + } } func TestReadFileAsLines(t *testing.T) { From 657985f4e8bb0767df6dfab71d5069b4f7ce88b2 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 28 Apr 2023 16:54:55 +0200 Subject: [PATCH 5/5] Removed now useless error from IsInsideDir --- paths.go | 8 +++++--- paths_test.go | 12 +++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/paths.go b/paths.go index 52c036c..a9e752b 100644 --- a/paths.go +++ b/paths.go @@ -188,15 +188,17 @@ func (p *Path) Clean() *Path { // IsInsideDir returns true if the current path is inside the provided // dir -func (p *Path) IsInsideDir(dir *Path) (bool, error) { +func (p *Path) IsInsideDir(dir *Path) bool { rel, err := filepath.Rel(dir.path, p.path) if err != nil { // If the dir cannot be made relative to this path it means // that it belong to a different filesystems, so it cannot be // inside this path. - return false, nil + return false } - return !strings.Contains(rel, ".."+string(os.PathSeparator)) && rel != ".." && rel != ".", nil + return !strings.Contains(rel, ".."+string(os.PathSeparator)) && + rel != ".." && + rel != "." } // Parent returns all but the last element of path, typically the path's diff --git a/paths_test.go b/paths_test.go index 6b5f236..fba0481 100644 --- a/paths_test.go +++ b/paths_test.go @@ -155,15 +155,11 @@ func TestResetStatCacheWhenFollowingSymlink(t *testing.T) { func TestIsInsideDir(t *testing.T) { notInside := func(a, b *Path) { - in, err := a.IsInsideDir(b) - require.NoError(t, err) - require.False(t, in, "%s is inside %s", a, b) + require.False(t, a.IsInsideDir(b), "%s is inside %s", a, b) } inside := func(a, b *Path) { - in, err := a.IsInsideDir(b) - require.NoError(t, err) - require.True(t, in, "%s is inside %s", a, b) + require.True(t, a.IsInsideDir(b), "%s is inside %s", a, b) notInside(b, a) } @@ -381,9 +377,7 @@ func TestWriteToTempFile(t *testing.T) { defer tmp.Remove() require.NoError(t, err) require.True(t, strings.HasPrefix(tmp.Base(), "prefix")) - inside, err := tmp.IsInsideDir(tmpDir) - require.NoError(t, err) - require.True(t, inside) + require.True(t, tmp.IsInsideDir(tmpDir)) data, err := tmp.ReadFile() require.NoError(t, err) require.Equal(t, tmpData, data)