mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-04 10:39:47 -06:00
[server][core] Rename ResourceByRootedPath => ResourceByPathWithRoot
This commit is contained in:
@@ -18,7 +18,7 @@ func handleContentsRequest(c *gin.Context) {
|
||||
path := c.Param("path")
|
||||
|
||||
f := authenticator.GetFileSystem(c)
|
||||
r, err := f.ResourceByRootedPath(path)
|
||||
r, err := f.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func handleCopyRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
src, err := fs.ResourceByRootedPath(params.Src)
|
||||
src, err := fs.ResourceByPathWithRoot(params.Src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func handleDeleteRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
r, err := fs.ResourceByRootedPath(params.Path)
|
||||
r, err := fs.ResourceByPathWithRoot(params.Path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ func handleInfoRequest(c *gin.Context) {
|
||||
path := c.Param("path")
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
r, err := fs.ResourceByRootedPath(path)
|
||||
r, err := fs.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func handleMkdirRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
parent, err := fs.ResourceByRootedPath(params.Parent)
|
||||
parent, err := fs.ResourceByPathWithRoot(params.Parent)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func handleMoveRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
r, err := fs.ResourceByRootedPath(params.Src)
|
||||
r, err := fs.ResourceByPathWithRoot(params.Src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func handleShareRequest(c *gin.Context) {
|
||||
}
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
r, err := fs.ResourceByRootedPath(params.Path)
|
||||
r, err := fs.ResourceByPathWithRoot(params.Path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func handleDiskUsageRequest(c *gin.Context) {
|
||||
path := c.Query("path")
|
||||
|
||||
fs := authenticator.GetFileSystem(c)
|
||||
resource, err := fs.ResourceByRootedPath(path)
|
||||
resource, err := fs.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func handleUploadRequest(c *gin.Context) {
|
||||
|
||||
f := authenticator.GetFileSystem(c)
|
||||
err := f.RunInTx(func(f fs.FileSystem) error {
|
||||
parent, err := f.ResourceByRootedPath(params.Parent)
|
||||
parent, err := f.ResourceByPathWithRoot(params.Parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func SetupRoutes(r *gin.RouterGroup) {
|
||||
func handleHomeRoute(c *gin.Context) {
|
||||
user := authenticator.GetUser(c)
|
||||
f := authenticator.GetFileSystem(c)
|
||||
r, err := f.ResourceByRootedPath("")
|
||||
r, err := f.ResourceByPathWithRoot("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func setupCatCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
path := args[0]
|
||||
r, err := f.ResourceByRootedPath(path)
|
||||
r, err := f.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
fmt.Println("cannot open'" + path + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -18,7 +18,7 @@ func setupCpCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
srcPath := args[0]
|
||||
src, err := f.ResourceByRootedPath(srcPath)
|
||||
src, err := f.ResourceByPathWithRoot(srcPath)
|
||||
if err != nil {
|
||||
fmt.Println("cannot copy'" + srcPath + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -29,7 +29,7 @@ func setupImportCommand() *cobra.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
destParent, err := f.ResourceByRootedPath(args[1])
|
||||
destParent, err := f.ResourceByPathWithRoot(args[1])
|
||||
if err != nil {
|
||||
fmt.Println("unable to find '" + args[1] + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -22,7 +22,7 @@ func setupLsCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
pathOrUUID := args[0]
|
||||
r, err := f.ResourceByRootedPath(pathOrUUID)
|
||||
r, err := f.ResourceByPathWithRoot(pathOrUUID)
|
||||
if err != nil {
|
||||
fmt.Println("unable to find '" + pathOrUUID + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -17,7 +17,7 @@ func setupMvCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
srcPath := args[0]
|
||||
src, err := f.ResourceByRootedPath(srcPath)
|
||||
src, err := f.ResourceByPathWithRoot(srcPath)
|
||||
if err != nil {
|
||||
fmt.Println("cannot move'" + srcPath + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -17,7 +17,7 @@ func setupPublinksCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
pathOrUUID := args[0]
|
||||
r, err := f.ResourceByRootedPath(pathOrUUID)
|
||||
r, err := f.ResourceByPathWithRoot(pathOrUUID)
|
||||
if err != nil {
|
||||
fmt.Println("cannot list publinks for '" + pathOrUUID + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -16,7 +16,7 @@ func setupRmCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
pathOrUUID := args[0]
|
||||
r, err := f.ResourceByRootedPath(pathOrUUID)
|
||||
r, err := f.ResourceByPathWithRoot(pathOrUUID)
|
||||
if err != nil {
|
||||
fmt.Println("cannot remove '" + pathOrUUID + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -20,7 +20,7 @@ func setupSetfaclCommand() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
f := common.UserFileSystem(cmd)
|
||||
path := args[0]
|
||||
r, err := f.ResourceByRootedPath(path)
|
||||
r, err := f.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
fmt.Println("cannot update permissions for '" + path + "': " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -33,7 +33,7 @@ func setupCreateCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
func createPublink(f fs.FileSystem, name, path string, password string, durationStr string, accesses int) error {
|
||||
r, err := f.ResourceByRootedPath(path)
|
||||
r, err := f.ResourceByPathWithRoot(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func setupBookmarksRemoveCommand() *cobra.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r, err := common.UserFileSystem(cmd).ResourceByRootedPath(args[0])
|
||||
r, err := common.UserFileSystem(cmd).ResourceByPathWithRoot(args[0])
|
||||
if err != nil {
|
||||
fmt.Println("unable to remove bookmark: " + err.Error())
|
||||
os.Exit(1)
|
||||
@@ -88,7 +88,7 @@ func setupBookmarksAddCommand() *cobra.Command {
|
||||
fmt.Println("unable to add bookmark: user not specified")
|
||||
os.Exit(1)
|
||||
}
|
||||
r, err := common.UserFileSystem(cmd).ResourceByRootedPath(args[0])
|
||||
r, err := common.UserFileSystem(cmd).ResourceByPathWithRoot(args[0])
|
||||
if err != nil {
|
||||
fmt.Println("unable to add bookmark: " + err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -31,7 +31,7 @@ func setupUserModCommand() *cobra.Command {
|
||||
var homeID pgtype.UUID
|
||||
path, _ := cmd.Flags().GetString("home")
|
||||
if path != "" {
|
||||
if r, err := rootFS.ResourceByRootedPath(path); err != nil {
|
||||
if r, err := rootFS.ResourceByPathWithRoot(path); err != nil {
|
||||
fmt.Println("invalid value for flag 'home': " + err.Error())
|
||||
os.Exit(1)
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@ func (f filesystem) CreateResourceByPath(path string, dir, recursive bool, confl
|
||||
index := strings.LastIndex(path, "/")
|
||||
name := path[index+1:]
|
||||
parentPath := path[0:index]
|
||||
parent, err := f.ResourceByPath(parentPath)
|
||||
parent, err := f.ResourceByPathWithRoot(parentPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrResourceNotFound) {
|
||||
if recursive {
|
||||
|
||||
@@ -8,6 +8,32 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func (f filesystem) ResourceByID(id uuid.UUID) (Resource, error) {
|
||||
const query = "SELECT r.*, (SELECT " + publinkFieldsQuery + " FROM publinks l WHERE l.root = r.id) AS links FROM resources r WHERE id = $1::UUID"
|
||||
if rows, err := f.db.Query(query, id); err != nil {
|
||||
return Resource{}, err
|
||||
} else {
|
||||
return f.collectResource(rows, true)
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesystem) ResourceByPathWithRoot(ref string) (Resource, error) {
|
||||
i := strings.Index(ref, ":")
|
||||
|
||||
if i >= 0 {
|
||||
if ref[0] == '/' {
|
||||
ref = ref[1:]
|
||||
i -= 1
|
||||
}
|
||||
id, err := uuid.Parse(ref[:i])
|
||||
if err != nil {
|
||||
return Resource{}, ErrResourceNotFound
|
||||
}
|
||||
f = f.withPathRoot(pgtype.UUID{Bytes: id, Valid: true})
|
||||
}
|
||||
return f.ResourceByPath(ref[i+1:])
|
||||
}
|
||||
|
||||
func (f filesystem) ResourceByPath(path string) (Resource, error) {
|
||||
if !f.pathRoot.Valid {
|
||||
return Resource{}, ErrResourceNotFound
|
||||
@@ -45,15 +71,6 @@ func (f filesystem) ResourceByPath(path string) (Resource, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesystem) ResourceByID(id uuid.UUID) (Resource, error) {
|
||||
const query = "SELECT r.*, (SELECT " + publinkFieldsQuery + " FROM publinks l WHERE l.root = r.id) AS links FROM resources r WHERE id = $1::UUID"
|
||||
if rows, err := f.db.Query(query, id); err != nil {
|
||||
return Resource{}, err
|
||||
} else {
|
||||
return f.collectResource(rows, true)
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesystem) childResourceByName(parentID uuid.UUID, name string) (Resource, error) {
|
||||
const query = "SELECT * FROM resources WHERE parent = $1::UUID AND name = $2::TEXT AND deleted IS NULL"
|
||||
if rows, err := f.db.Query(query, parentID, name); err != nil {
|
||||
@@ -62,20 +79,3 @@ func (f filesystem) childResourceByName(parentID uuid.UUID, name string) (Resour
|
||||
return f.collectResource(rows, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (f filesystem) ResourceByRootedPath(ref string) (Resource, error) {
|
||||
i := strings.Index(ref, ":")
|
||||
|
||||
if i >= 0 {
|
||||
if ref[0] == '/' {
|
||||
ref = ref[1:]
|
||||
i -= 1
|
||||
}
|
||||
id, err := uuid.Parse(ref[:i])
|
||||
if err != nil {
|
||||
return Resource{}, ErrResourceNotFound
|
||||
}
|
||||
f = f.withPathRoot(pgtype.UUID{Bytes: id, Valid: true})
|
||||
}
|
||||
return f.ResourceByPath(ref[i+1:])
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ type FileSystem interface {
|
||||
|
||||
// find.go
|
||||
ResourceByID(id uuid.UUID) (Resource, error)
|
||||
ResourceByPath(path string) (Resource, error)
|
||||
ResourceByRootedPath(ref string) (Resource, error)
|
||||
ResourceByPath(ref string) (Resource, error)
|
||||
ResourceByPathWithRoot(ref string) (Resource, error)
|
||||
|
||||
// search.go
|
||||
Search(query string, includeDeleted bool) ([]Resource, error)
|
||||
|
||||
@@ -73,7 +73,7 @@ func (r Resource) RestoreDeleted(parentPathOrUUID string, name string, autoRenam
|
||||
err = ErrResourceNotFound
|
||||
}
|
||||
} else {
|
||||
p, err = r.f.ResourceByRootedPath(parentPathOrUUID)
|
||||
p, err = r.f.ResourceByPathWithRoot(parentPathOrUUID)
|
||||
}
|
||||
if err == ErrResourceNotFound {
|
||||
err = ErrParentNotFound
|
||||
|
||||
Reference in New Issue
Block a user