Fix username path munging.

This commit is contained in:
Solderpunk 2019-04-06 21:01:42 +03:00
parent 6f93dc967d
commit 46621b9617
1 changed files with 7 additions and 8 deletions

View File

@ -36,18 +36,17 @@ func GetHandler(config Config) http.HandlerFunc {
return
}
// Resolve URI path to actual filesystem path
// fmt.Println(r.URL.Path)
bits := filepath.SplitList(r.URL.Path)
// fmt.Println(bits[0])
path := r.URL.Path
if strings.HasPrefix(bits[0], "/~") {
bits[0] = strings.Replace(bits[0], "/~", "/home/", 1)
bits[0] += config.HomeDocBase
path = filepath.Join(bits...)
if strings.HasPrefix(path, "/~") {
bits := strings.Split(r.URL.Path, "/")
username := bits[1][1:]
//strings.Replace(bits[1], "~", "", 1)
new_prefix := filepath.Join("home", username, config.HomeDocBase)
path = strings.Replace(path, bits[1], new_prefix, 1)
} else {
path = filepath.Join(config.DocBase, r.URL.Path)
}
// fmt.Println(path)
//fmt.Println(path)
// Fail if file does not exist
info, err := os.Stat(path)
if os.IsNotExist(err) {