Skip to content

Commit

Permalink
Lock the proper file
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck authored and butonic committed Jul 3, 2023
1 parent 0c47ce5 commit eec05ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (lu *Lookup) CopyMetadataWithSourceLock(ctx context.Context, sourcePath, ta
switch {
case lockedSource == nil:
return errors.New("no lock provided")
case lockedSource.File.Name() != lu.MetadataBackend().MetadataPath(sourcePath):
case lockedSource.File.Name() != lu.MetadataBackend().MetadataPath(sourcePath)+".lock":
return errors.New("lockpath does not match filepath")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,11 @@ func (b MessagePackBackend) saveAttributes(ctx context.Context, path string, set
_, subspan := tracer.Start(ctx, "lockedfile.OpenFile")
f, err = lockedfile.OpenFile(lockPath, os.O_RDWR|os.O_CREATE, 0600)
subspan.End()
} else {
_, subspan := tracer.Start(ctx, "os.OpenFile")
f, err = os.OpenFile(lockPath, os.O_RDWR|os.O_CREATE, 0600)
subspan.End()
defer f.Close()
}
if err != nil {
return err
}
defer f.Close()

// Read current state
_, subspan := tracer.Start(ctx, "os.ReadFile")
Expand Down Expand Up @@ -202,7 +198,7 @@ func (b MessagePackBackend) saveAttributes(ctx context.Context, path string, set

go func() { _ = b.metaCache.PushToCache(b.cacheKey(path), attribs) }()

return f.Close()
return nil
}

func (b MessagePackBackend) loadAttributes(ctx context.Context, path string, source io.Reader) (map[string][]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func initNewNode(upload *Upload, n *node.Node, fsize uint64) (*lockedfile.File,
}

// create and write lock new node metadata
f, err := lockedfile.OpenFile(upload.lu.MetadataBackend().MetadataPath(n.InternalPath()), os.O_RDWR|os.O_CREATE, 0600)
f, err := lockedfile.OpenFile(upload.lu.MetadataBackend().MetadataPath(n.InternalPath())+".lock", os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -403,7 +403,7 @@ func updateExistingNode(upload *Upload, n *node.Node, spaceID string, fsize uint
targetPath := n.InternalPath()

// write lock existing node before reading treesize or tree time
f, err := lockedfile.OpenFile(upload.lu.MetadataBackend().MetadataPath(targetPath), os.O_RDWR, 0600)
f, err := lockedfile.OpenFile(upload.lu.MetadataBackend().MetadataPath(targetPath)+".lock", os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit eec05ce

Please sign in to comment.