Skip to content

Commit f3617b8

Browse files
fnoopvSystem-Glitch
authored andcommitted
Fix duplicate path join in OS filesystem utility
1 parent 136b3fe commit f3617b8

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

util/fsutil/osfs/osfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ func (*FS) Getwd() (string, error) {
7272
// FileExists returns true if the file at the given path exists and is readable.
7373
// Returns false if the given file is a directory.
7474
func (f *FS) FileExists(name string) bool {
75-
if stats, err := f.Stat(path.Join(f.dir, name)); err == nil {
75+
if stats, err := f.Stat(name); err == nil {
7676
return !stats.IsDir()
7777
}
7878
return false
7979
}
8080

8181
// IsDirectory returns true if the file at the given path exists, is a directory and is readable.
8282
func (f *FS) IsDirectory(name string) bool {
83-
if stats, err := f.Stat(path.Join(f.dir, name)); err == nil {
83+
if stats, err := f.Stat(name); err == nil {
8484
return stats.IsDir()
8585
}
8686
return false

util/fsutil/osfs/osfs_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,27 @@ func TestOSFS(t *testing.T) {
9999
assert.False(t, fs.FileExists("resources/notafile.txt"))
100100
})
101101

102+
t.Run("FileExistsWithBaseDir", func(t *testing.T) {
103+
fs := New("resources")
104+
assert.True(t, fs.FileExists("test_file.txt"))
105+
assert.False(t, fs.FileExists("lang"))
106+
assert.False(t, fs.FileExists("notafile.txt"))
107+
})
108+
102109
t.Run("IsDirectory", func(t *testing.T) {
103110
fs := &FS{}
104111
assert.False(t, fs.IsDirectory("resources/test_file.txt"))
105112
assert.True(t, fs.IsDirectory("resources"))
106113
assert.False(t, fs.IsDirectory("resources/notadir"))
107114
})
108115

116+
t.Run("IsDirectoryWithBaseDir", func(t *testing.T) {
117+
fs := New("resources")
118+
assert.False(t, fs.IsDirectory("test_file.txt"))
119+
assert.True(t, fs.IsDirectory("lang"))
120+
assert.False(t, fs.IsDirectory("notadir"))
121+
})
122+
109123
t.Run("Mkdir", func(t *testing.T) {
110124
fs := &FS{}
111125
path := "resources/testdir"

0 commit comments

Comments
 (0)