Skip to content

Commit 657985f

Browse files
committed
Removed now useless error from IsInsideDir
1 parent 8780dcc commit 657985f

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Diff for: paths.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,17 @@ func (p *Path) Clean() *Path {
188188

189189
// IsInsideDir returns true if the current path is inside the provided
190190
// dir
191-
func (p *Path) IsInsideDir(dir *Path) (bool, error) {
191+
func (p *Path) IsInsideDir(dir *Path) bool {
192192
rel, err := filepath.Rel(dir.path, p.path)
193193
if err != nil {
194194
// If the dir cannot be made relative to this path it means
195195
// that it belong to a different filesystems, so it cannot be
196196
// inside this path.
197-
return false, nil
197+
return false
198198
}
199-
return !strings.Contains(rel, ".."+string(os.PathSeparator)) && rel != ".." && rel != ".", nil
199+
return !strings.Contains(rel, ".."+string(os.PathSeparator)) &&
200+
rel != ".." &&
201+
rel != "."
200202
}
201203

202204
// Parent returns all but the last element of path, typically the path's

Diff for: paths_test.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,11 @@ func TestResetStatCacheWhenFollowingSymlink(t *testing.T) {
155155

156156
func TestIsInsideDir(t *testing.T) {
157157
notInside := func(a, b *Path) {
158-
in, err := a.IsInsideDir(b)
159-
require.NoError(t, err)
160-
require.False(t, in, "%s is inside %s", a, b)
158+
require.False(t, a.IsInsideDir(b), "%s is inside %s", a, b)
161159
}
162160

163161
inside := func(a, b *Path) {
164-
in, err := a.IsInsideDir(b)
165-
require.NoError(t, err)
166-
require.True(t, in, "%s is inside %s", a, b)
162+
require.True(t, a.IsInsideDir(b), "%s is inside %s", a, b)
167163
notInside(b, a)
168164
}
169165

@@ -381,9 +377,7 @@ func TestWriteToTempFile(t *testing.T) {
381377
defer tmp.Remove()
382378
require.NoError(t, err)
383379
require.True(t, strings.HasPrefix(tmp.Base(), "prefix"))
384-
inside, err := tmp.IsInsideDir(tmpDir)
385-
require.NoError(t, err)
386-
require.True(t, inside)
380+
require.True(t, tmp.IsInsideDir(tmpDir))
387381
data, err := tmp.ReadFile()
388382
require.NoError(t, err)
389383
require.Equal(t, tmpData, data)

0 commit comments

Comments
 (0)