Skip to content

Commit 7d88805

Browse files
authored
Merge pull request #22 from arduino/restore-1.x-compatibility
Restore 1.x.x compatibility
2 parents aa361d8 + 0bc48d6 commit 7d88805

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

paths.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,17 +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 {
191+
func (p *Path) IsInsideDir(dir *Path) (bool, error) {
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
197+
return false, nil
198198
}
199199
return !strings.Contains(rel, ".."+string(os.PathSeparator)) &&
200200
rel != ".." &&
201-
rel != "."
201+
rel != ".", nil
202202
}
203203

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

paths_test.go

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

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

161163
inside := func(a, b *Path) {
162-
require.True(t, a.IsInsideDir(b), "%s is inside %s", a, b)
164+
isInside, err := a.IsInsideDir(b)
165+
require.NoError(t, err)
166+
require.True(t, isInside, "%s is inside %s", a, b)
163167
notInside(b, a)
164168
}
165169

@@ -377,7 +381,9 @@ func TestWriteToTempFile(t *testing.T) {
377381
defer tmp.Remove()
378382
require.NoError(t, err)
379383
require.True(t, strings.HasPrefix(tmp.Base(), "prefix"))
380-
require.True(t, tmp.IsInsideDir(tmpDir))
384+
isInside, err := tmp.IsInsideDir(tmpDir)
385+
require.NoError(t, err)
386+
require.True(t, isInside)
381387
data, err := tmp.ReadFile()
382388
require.NoError(t, err)
383389
require.Equal(t, tmpData, data)

0 commit comments

Comments
 (0)