8000 Merge pull request #311 from danfletcher1/master · etherscan-io/sftp@515578a · GitHub
[go: up one dir, main page]

Skip to content

Commit 515578a

Browse files
authored
Merge pull request pkg#311 from danfletcher1/master
Bug with sub folders/files of a renamed/removed path
2 parents 4350932 + e9514f4 commit 515578a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

request-example.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313
"sort"
14+
"strings"
1415
"sync"
1516
"syscall"
1617
"time"
@@ -90,12 +91,36 @@ func (fs *root) Filecmd(r *Request) error {
9091
file.name = r.Target
9192
fs.files[r.Target] = file
9293
delete(fs.files, r.Filepath)
94+
95+
if file.IsDir() {
96+
for path, file := range fs.files {
97+
if strings.HasPrefix(path, r.Filepath+"/") {
98+
file.name = r.Target + path[len(r.Filepath):]
99+
fs.files[r.Target+path[len(r.Filepath):]] = file
100+
delete(fs.files, path)
101+
}
102+
}
103+
}
93104
case "Rmdir", "Remove":
94-
_, err := fs.fetch(filepath.Dir(r.Filepath))
105+
file, err := fs.fetch(filepath.Dir(r.Filepath))
95106
if err != nil {
96107
return err
97108
}
109+
110+
if file.IsDir() {
111+
for path := range fs.files {
112+
if strings.HasPrefix(path, r.Filepath+"/") {
113+
return &os.PathError{
114+
Op: "remove",
115+
Path: r.Filepath + "/",
116+
Err: fmt.Errorf("directory is not empty"),
117+
}
118+
}
119+
}
120+
}
121+
98122
delete(fs.files, r.Filepath)
123+
99124
case "Mkdir":
100125
_, err := fs.fetch(filepath.Dir(r.Filepath))
101126
if err != nil {

0 commit comments

Comments
 (0)
0