Skip to content

Commit 166a88c

Browse files
committed
fixed call to filepath.Clean() in archives.Set()
this fixes an issue on Windows where ROM selector could not navigate backwards out of the installation folder. Issue #30
1 parent e97629f commit 166a88c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

archivefs/archivefs_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package archivefs_test
1818
import (
1919
"fmt"
2020
"io"
21+
"os"
2122
"path/filepath"
2223
"testing"
2324

@@ -31,6 +32,13 @@ func TestArchivefsPath(t *testing.T) {
3132
var entries []archivefs.Entry
3233
var err error
3334

35+
// get working directory for test. we need this so we can modify the testing
36+
// path for comparison with result from the archivefs.Set() function
37+
wd, err := os.Getwd()
38+
test.ExpectSuccess(t, err)
39+
wd, err = filepath.Abs(wd)
40+
test.ExpectSuccess(t, err)
41+
3442
// non-existant file
3543
path = "foo"
3644
err = afs.Set(path, false)
@@ -41,7 +49,7 @@ func TestArchivefsPath(t *testing.T) {
4149
path = "testdir"
4250
err = afs.Set(path, false)
4351
test.ExpectSuccess(t, err)
44-
test.ExpectEquality(t, afs.String(), path)
52+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
4553
test.ExpectSuccess(t, afs.IsDir())
4654
test.ExpectSuccess(t, !afs.InArchive())
4755

@@ -61,7 +69,7 @@ func TestArchivefsPath(t *testing.T) {
6169
path = filepath.Join("testdir", "testfile")
6270
err = afs.Set(path, false)
6371
test.ExpectSuccess(t, err)
64-
test.ExpectEquality(t, afs.String(), path)
72+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
6573
test.ExpectSuccess(t, !afs.IsDir())
6674
test.ExpectSuccess(t, !afs.InArchive())
6775

@@ -76,7 +84,7 @@ func TestArchivefsPath(t *testing.T) {
7684
path = filepath.Join("testdir", "testarchive.zip")
7785
err = afs.Set(path, false)
7886
test.ExpectSuccess(t, err)
79-
test.ExpectEquality(t, afs.String(), path)
87+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
8088
test.ExpectSuccess(t, afs.IsDir())
8189
test.ExpectSuccess(t, afs.InArchive())
8290

@@ -90,15 +98,15 @@ func TestArchivefsPath(t *testing.T) {
9098
path = filepath.Join("testdir", "testarchive.zip", "archivefile1")
9199
err = afs.Set(path, false)
92100
test.ExpectSuccess(t, err)
93-
test.ExpectEquality(t, afs.String(), path)
101+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
94102
test.ExpectSuccess(t, !afs.IsDir())
95103
test.ExpectSuccess(t, afs.InArchive())
96104

97105
// directory a real archive
98106
path = filepath.Join("testdir", "testarchive.zip", "archivedir")
99107
err = afs.Set(path, false)
100108
test.ExpectSuccess(t, err)
101-
test.ExpectEquality(t, afs.String(), path)
109+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
102110
test.ExpectSuccess(t, afs.IsDir())
103111
test.ExpectSuccess(t, afs.InArchive())
104112

@@ -112,7 +120,7 @@ func TestArchivefsPath(t *testing.T) {
112120
path = filepath.Join("testdir", "testarchive.zip", "archivedir", "archivefile3")
113121
err = afs.Set(path, false)
114122
test.ExpectSuccess(t, err)
115-
test.ExpectEquality(t, afs.String(), path)
123+
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
116124
test.ExpectSuccess(t, !afs.IsDir())
117125
test.ExpectSuccess(t, afs.InArchive())
118126
}

archivefs/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (afs *Path) Set(path string, fallback bool) error {
359359
}
360360

361361
// make sure path is clean
362-
afs.current = filepath.Clean(search)
362+
afs.current = filepath.Clean(afs.current)
363363

364364
return nil
365365
}

0 commit comments

Comments
 (0)