-
Notifications
You must be signed in to change notification settings - Fork 56
/
mkdir.go
47 lines (40 loc) · 1.06 KB
/
mkdir.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
41
42
43
44
45
46
47
package serverHandler
import (
"errors"
"net/http"
"os"
"strings"
)
func (h *handler) mkdirs(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 = getCleanDirFilePath(inputFilename); !ok {
errs = append(errs, errors.New("mkdir: illegal directory path "+inputFilename))
continue
}
filenamePart1 := filename
if prefixEndIndex := strings.IndexByte(filenamePart1, '/'); prefixEndIndex > 0 {
filenamePart1 = filenamePart1[0:prefixEndIndex]
}
if containsItem(aliasSubItems, filenamePart1) {
errs = append(errs, errors.New("mkdir: ignore path shadowed by alias "+filename))
continue
}
fsPath := fsPrefix + "/" + filename
h.logMutate(authUserName, "mkdir", fsPath, r)
err := os.MkdirAll(fsPath, 0755)
if err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
go h.logger.LogErrors(errs...)
return false
}
return true
}