docstore/pkg/fs/helper.go
2021-02-18 22:36:49 +01:00

50 lines
845 B
Go

// Copyright (C) 2019 Marius Schellenberger
package fs
import (
"errors"
"git.giftfish.de/ston1th/docstore/pkg/core"
"path/filepath"
"strings"
)
const sep = "/"
func Clean(path string) string {
return filepath.FromSlash(filepath.Clean(sep + path))
}
func File(path string) string {
_, f := filepath.Split(Clean(path))
return f
}
var reserved = []string{
core.TotpURI,
core.LoginURI,
core.LogoutURI,
core.SearchURI,
core.LogsURI,
core.TagsURI,
core.StatsURI,
core.UserURI,
core.RawPrefix,
core.IndexPrefix,
core.RetagPrefix,
core.UploadPrefix,
core.NewPrefix,
core.MovePrefix,
core.DeletePrefix,
core.WebDavPrefix,
core.StaticPrefix,
}
func checkPath(path string) error {
for _, p := range reserved {
if strings.HasPrefix(path, p) {
return errors.New("base path '" + p + "' is reserved")
}
}
return nil
}