From af22f00cb939334faeeea0afc24f53ddd8a63ed3 Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Wed, 26 Mar 2025 22:25:28 +0530 Subject: [PATCH] [server][core] Make Resource.parentID not a pointer --- server/internal/api/v1/fs/ls.go | 30 +++++++++++----------- server/internal/core/db/models.go | 2 +- server/internal/core/fs/ancestors.go | 2 +- server/internal/core/fs/copy_move.go | 8 +++--- server/internal/core/fs/resource.go | 4 +-- server/internal/core/fs/resource_delete.go | 10 ++++---- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/internal/api/v1/fs/ls.go b/server/internal/api/v1/fs/ls.go index ce51920e..5efd1352 100644 --- a/server/internal/api/v1/fs/ls.go +++ b/server/internal/api/v1/fs/ls.go @@ -10,24 +10,24 @@ import ( ) type AncestorResponse struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` - ParentID *uuid.UUID `json:"parent"` - Permissions string `json:"permissions"` + ID uuid.UUID `json:"id"` + Name string `json:"name"` + ParentID uuid.UUID `json:"parent"` + Permissions string `json:"permissions"` } type InfoResponse struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` - ParentID *uuid.UUID `json:"parent"` - Dir bool `json:"dir"` - Created time.Time `json:"created"` - Modified time.Time `json:"modified"` - ContentLength int64 `json:"c_len"` - ContentType string `json:"c_type"` - ContentSHA256 string `json:"c_sha256"` - Permissions string `json:"permissions"` - Grants string `json:"grants"` + ID uuid.UUID `json:"id"` + Name string `json:"name"` + ParentID uuid.UUID `json:"parent"` + Dir bool `json:"dir"` + Created time.Time `json:"created"` + Modified time.Time `json:"modified"` + ContentLength int64 `json:"c_len"` + ContentType string `json:"c_type"` + ContentSHA256 string `json:"c_sha256"` + Permissions string `json:"permissions"` + Grants string `json:"grants"` } type FullResponse struct { diff --git a/server/internal/core/db/models.go b/server/internal/core/db/models.go index 85b26d1d..682a9699 100644 --- a/server/internal/core/db/models.go +++ b/server/internal/core/db/models.go @@ -42,7 +42,7 @@ type Publink struct { type Resource struct { ID uuid.UUID Name string - Parent *uuid.UUID + Parent uuid.UUID Dir bool Created pgtype.Timestamp Modified pgtype.Timestamp diff --git a/server/internal/core/fs/ancestors.go b/server/internal/core/fs/ancestors.go index b6afa4a4..7906ea8a 100644 --- a/server/internal/core/fs/ancestors.go +++ b/server/internal/core/fs/ancestors.go @@ -9,7 +9,7 @@ import ( type ResourceAncestor struct { ID uuid.UUID - ParentID *uuid.UUID + ParentID uuid.UUID Name string Permissions []byte } diff --git a/server/internal/core/fs/copy_move.go b/server/internal/core/fs/copy_move.go index 7c182630..16416afc 100644 --- a/server/internal/core/fs/copy_move.go +++ b/server/internal/core/fs/copy_move.go @@ -15,12 +15,12 @@ type copySrcDest struct { } func (r Resource) Move(target string, conflictResolution ResourceBindConflictResolution) (Resource, bool, error) { - if r.ParentID() == nil { + if r.ParentID() == uuid.Nil { return Resource{}, false, ErrInsufficientPermissions } // Check source directory permissions - parent, err := r.f.ResourceByID(*r.ParentID()) + parent, err := r.f.ResourceByID(r.ParentID()) if err != nil { return Resource{}, false, err } @@ -145,7 +145,7 @@ func (r Resource) Copy(target string, id uuid.UUID, recursive bool, conflictReso for _, src := range tree { id, _ := uuid.NewV7() - parent := newIDs[*src.parentID] + parent := newIDs[src.parentID] children = append(children, db.CreateResourcesParams{ ID: id, @@ -232,7 +232,7 @@ func (f filesystem) targetByPathOrUUID(src Resource, pathOrUUID string) (Resourc return Resource{}, "", ErrResourceNameInvalid } - var parentID = *src.ParentID() + var parentID = src.ParentID() if index != 0 { if id, err := uuid.Parse(pathOrUUID[0:index]); err != nil { return Resource{}, "", err diff --git a/server/internal/core/fs/resource.go b/server/internal/core/fs/resource.go index 1dc12de6..5e9698aa 100644 --- a/server/internal/core/fs/resource.go +++ b/server/internal/core/fs/resource.go @@ -10,7 +10,7 @@ import ( type Resource struct { f filesystem id uuid.UUID - parentID *uuid.UUID + parentID uuid.UUID name string dir bool created time.Time @@ -25,7 +25,7 @@ type Resource struct { } func (r Resource) ID() uuid.UUID { return r.id } -func (r Resource) ParentID() *uuid.UUID { return r.parentID } +func (r Resource) ParentID() uuid.UUID { return r.parentID } func (r Resource) Name() string { return r.name } func (r Resource) Dir() bool { return r.dir } func (r Resource) Created() time.Time { return r.created } diff --git a/server/internal/core/fs/resource_delete.go b/server/internal/core/fs/resource_delete.go index 91d40de2..451ca577 100644 --- a/server/internal/core/fs/resource_delete.go +++ b/server/internal/core/fs/resource_delete.go @@ -36,17 +36,17 @@ func (r Resource) DeleteChildRecursive(name string) (Resource, error) { } func (r Resource) DeleteRecursive(softDelete bool) (Resource, error) { - if r.ParentID() == nil { + if r.ParentID() == uuid.Nil { return Resource{}, ErrInsufficientPermissions } - parent, err := r.f.ResourceByID(*r.ParentID()) + parent, err := r.f.ResourceByID(r.ParentID()) if err == nil && !parent.hasPermission(PermissionWrite) { err = ErrInsufficientPermissions } if err != nil { return Resource{}, err } - if err := r.f.deleteRecursive(r.ID(), *r.ParentID(), softDelete, false); err != nil { + if err := r.f.deleteRecursive(r.ID(), r.ParentID(), softDelete, false); err != nil { return Resource{}, err } deleted := time.Now() @@ -62,7 +62,7 @@ func (r Resource) DeleteRecursive(softDelete bool) (Resource, error) { func (r Resource) RestoreDeleted(parentPathOrUUID string, name string, autoRename bool) (res Resource, count int, size int64, err error) { var p Resource if parentPathOrUUID == "" { - p, err = r.f.ResourceByID(*r.parentID) + p, err = r.f.ResourceByID(r.parentID) } else { p, err = r.f.ResourceByPathOrUUID(parentPathOrUUID) } @@ -107,7 +107,7 @@ func (r Resource) RestoreDeleted(parentPathOrUUID string, name string, autoRenam } err = r.f.runInTx(func(f filesystem) error { - if p.id != *r.parentID || r.name != name { + if p.id != r.parentID || r.name != name { if update, err := f.db.UpdateResourceNameParent(f.ctx, db.UpdateResourceNameParentParams{ID: r.ID(), Name: name, Parent: p.id}); err != nil { if strings.Contains(err.Error(), "unique_member_resource_name") { return ErrResourceNameConflict