[server][core] Make Resource.parentID not a pointer

This commit is contained in:
Abhishek Shroff
2025-03-26 22:25:28 +05:30
parent f26434aba7
commit af22f00cb9
6 changed files with 28 additions and 28 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -9,7 +9,7 @@ import (
type ResourceAncestor struct {
ID uuid.UUID
ParentID *uuid.UUID
ParentID uuid.UUID
Name string
Permissions []byte
}

View File

@@ -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

View File

@@ -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 }

View File

@@ -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