Skip to content

Commit 1a92b10

Browse files
committed
Use path instead of filepath for virtual filesystem paths
1 parent 525a8e4 commit 1a92b10

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

httpfs.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package httpfs
77
import (
88
"net/http"
99
"os"
10-
"path/filepath"
10+
"path"
1111
"strings"
1212
"time"
1313

@@ -42,12 +42,13 @@ func (filer *Httpfs) Mkdir(name string, perm os.FileMode) error {
4242
// MkdirAll creates all missing directories in `name` without returning an error
4343
// for directories that already exist
4444
func (filer *Httpfs) MkdirAll(name string, perm os.FileMode) error {
45-
p := string(filepath.Separator)
46-
for _, name := range strings.Split(name, p) {
45+
// Virtual filesystems use forward slashes
46+
p := "/"
47+
for _, name := range strings.Split(name, "/") {
4748
if name == "" {
4849
continue
4950
}
50-
p = filepath.Join(p, name)
51+
p = path.Join(p, name)
5152
err := filer.Mkdir(p, perm)
5253
if err != nil && !os.IsExist(err) {
5354
return err
@@ -71,17 +72,17 @@ type RemoveAller interface {
7172
// RemoveAll removes a directory after removing all children of that directory.
7273
// If the underlying filesystem implements RemoveAller, it delegates to that.
7374
// Returns nil for non-existent paths (matching os.RemoveAll behavior).
74-
func (filer *Httpfs) RemoveAll(path string) error {
75+
func (filer *Httpfs) RemoveAll(pathname string) error {
7576
// Check if the underlying filesystem implements RemoveAll
7677
if ra, ok := filer.fs.(RemoveAller); ok {
77-
err := ra.RemoveAll(path)
78+
err := ra.RemoveAll(pathname)
7879
if os.IsNotExist(err) {
7980
return nil
8081
}
8182
return err
8283
}
8384

84-
info, err := filer.Stat(path)
85+
info, err := filer.Stat(pathname)
8586
if err != nil {
8687
if os.IsNotExist(err) {
8788
return nil
@@ -91,11 +92,11 @@ func (filer *Httpfs) RemoveAll(path string) error {
9192

9293
// If it's not a directory, just remove it
9394
if !info.IsDir() {
94-
return filer.Remove(path)
95+
return filer.Remove(pathname)
9596
}
9697

9798
// Open directory read-only to list entries
98-
f, err := filer.OpenFile(path, os.O_RDONLY, 0)
99+
f, err := filer.OpenFile(pathname, os.O_RDONLY, 0)
99100
if err != nil {
100101
if os.IsNotExist(err) {
101102
return nil
@@ -115,16 +116,16 @@ func (filer *Httpfs) RemoveAll(path string) error {
115116
if name == "." || name == ".." {
116117
continue
117118
}
118-
if err := filer.RemoveAll(filepath.Join(path, name)); err != nil {
119+
if err := filer.RemoveAll(path.Join(pathname, name)); err != nil {
119120
return err
120121
}
121122
}
122123

123-
err = filer.Remove(path)
124+
err = filer.Remove(pathname)
124125
// Some filesystems (e.g., memfs) return "directory not empty" even when
125126
// only . and .. remain. Check if the directory was actually removed.
126127
if err != nil {
127-
if _, statErr := filer.Stat(path); os.IsNotExist(statErr) {
128+
if _, statErr := filer.Stat(pathname); os.IsNotExist(statErr) {
128129
return nil
129130
}
130131
}

0 commit comments

Comments
 (0)