X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/469a638785e8562152dff4ba2e05e36b841c4d98..ba201a220aa723f98c6a81d74dc4229bf89b282a:/hotline/file_path.go diff --git a/hotline/file_path.go b/hotline/file_path.go index 97ce417..bb6bbd3 100644 --- a/hotline/file_path.go +++ b/hotline/file_path.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/binary" "errors" + "fmt" "io" "path/filepath" "strings" @@ -97,11 +98,20 @@ func (fp *FilePath) IsUploadDir() bool { return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "upload") } +func (fp *FilePath) IsUserDir() bool { + if fp.Len() == 0 { + return false + } + + return strings.HasPrefix(string(fp.Items[0].Name), "~") +} + + func (fp *FilePath) Len() uint16 { return binary.BigEndian.Uint16(fp.ItemCount[:]) } -func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) { +func ReadPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) { var fp FilePath if filePath != nil { if _, err = fp.Write(filePath); err != nil { @@ -119,6 +129,9 @@ func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err subPath, filepath.Join("/", string(fileName)), ) - + fullPath, err = txtDecoder.String(fullPath) + if err != nil { + return "", fmt.Errorf("invalid filepath encoding: %w", err) + } return fullPath, nil }