-
Notifications
You must be signed in to change notification settings - Fork 56
/
delete.go
40 lines (34 loc) · 809 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package serverHandler
import (
"errors"
"net/http"
"os"
)
func (h *handler) deleteItems(authUserName, fsPrefix string, files []string, aliasSubItems []os.FileInfo, r *http.Request) bool {
errs := []error{}
for _, inputFilename := range files {
if len(inputFilename) == 0 {
continue
}
var filename string
var ok bool
if filename, ok = getCleanFilePath(inputFilename); !ok {
errs = append(errs, errors.New("delete: illegal item name "+inputFilename))
continue
}
if containsItem(aliasSubItems, filename) {
continue
}
fsPath := fsPrefix + "/" + filename
h.logMutate(authUserName, "delete", fsPath, r)
err := os.RemoveAll(fsPath)
if err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
go h.logger.LogErrors(errs...)
return false
}
return true
}