Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion code/go/0chain.net/blobbercore/allocation/newdirchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/util"
"github.com/0chain/blobber/code/go/0chain.net/core/common"
"github.com/0chain/blobber/code/go/0chain.net/core/encryption"
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
"go.uber.org/zap"
"gorm.io/gorm"
)

Expand All @@ -33,6 +35,19 @@ func (nf *NewDir) ApplyChange(ctx context.Context,
if parentRef == nil || parentRef.ID == 0 {
_, err = reference.Mkdir(ctx, nf.AllocationID, nf.Path, allocationVersion, ts, collector)
} else {
collector.LockTransaction()
defer collector.UnlockTransaction()
dirLookupHash := reference.GetReferenceLookup(nf.AllocationID, nf.Path)
dRef, err := reference.GetLimitedRefFieldsByLookupHash(ctx, nf.AllocationID, dirLookupHash, []string{"id"})
if err != nil && err != gorm.ErrRecordNotFound {
logging.Logger.Error("ApplyChange:Newdir", zap.Error(err))
return err
}
err = nil
// already exists
if dRef != nil && dRef.ID != 0 {
return nil
}
parentIDRef := &parentRef.ID
newRef := reference.NewDirectoryRef()
newRef.AllocationID = nf.AllocationID
Expand All @@ -43,7 +58,7 @@ func (nf *NewDir) ApplyChange(ctx context.Context,
newRef.Name = filepath.Base(nf.Path)
newRef.PathLevel = len(strings.Split(strings.TrimRight(nf.Path, "/"), "/"))
newRef.ParentID = parentIDRef
newRef.LookupHash = reference.GetReferenceLookup(nf.AllocationID, nf.Path)
newRef.LookupHash = dirLookupHash
newRef.CreatedAt = ts
newRef.UpdatedAt = ts
newRef.FileMetaHash = encryption.FastHash(newRef.GetFileMetaHashData())
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/reference/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func Mkdir(ctx context.Context, allocationID, destpath string, allocationVersion
newRef.AllocationVersion = allocationVersion
err = db.Create(newRef).Error
if err != nil {
logging.Logger.Error("mkdir: failed to create directory", zap.Error(err), zap.String("path", fields[i]))
return nil, err
}
collector.AddToCache(newRef)
Expand Down
Loading