package fstore import ( "path/filepath" "strconv" "git.crumpington.com/public/jldb/lib/errs" ) func filesRootPath(rootDir string) string { return filepath.Clean(filepath.Join(rootDir, "files")) } func repDirPath(rootDir string) string { return filepath.Clean(filepath.Join(rootDir, "rep")) } func tempDirPath(rootDir string) string { return filepath.Clean(filepath.Join(rootDir, "tmp")) } func tempFilePath(inDir string, id uint64) string { return filepath.Join(inDir, strconv.FormatUint(id, 10)) } func validatePath(p string) error { if len(p) == 0 { return errs.InvalidPath.WithMsg("empty path") } if p[0] != '/' { return errs.InvalidPath.WithMsg("path must be absolute") } for _, c := range p { switch c { case '/', '-', '_', '.': continue default: } if c >= 'a' && c <= 'z' { continue } if c >= '0' && c <= '9' { continue } return errs.InvalidPath.WithMsg("invalid character in path: %s", string([]rune{c})) } return nil } func cleanPath(p string) string { if len(p) == 0 { return "/" } if p[0] != '/' { p = "/" + p } return filepath.Clean(p) }