Skip to content

Commit

Permalink
fix: chunked upload of existing file creates new version
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jul 19, 2021
1 parent 7df477f commit 0cc96aa
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

log := appctx.GetLogger(ctx)

var relative string // the internal path of the file node

n, err := fs.lu.NodeFromResource(ctx, ref)
n, err := fs.lookupNode(ctx, ref.Path)
if err != nil {
return nil, err
}

// permissions are checked in NewUpload below

relative, err = fs.lu.Path(ctx, n)
relative, err := fs.lu.Path(ctx, n)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,7 +205,7 @@ func (fs *Decomposedfs) NewUpload(ctx context.Context, info tusd.FileInfo) (uplo
}
info.MetaData["dir"] = filepath.Clean(info.MetaData["dir"])

n, err := fs.lu.NodeFromPath(ctx, filepath.Join(info.MetaData["dir"], info.MetaData["filename"]))
n, err := fs.lookupNode(ctx, filepath.Join(info.MetaData["dir"], info.MetaData["filename"]))
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error wrapping filename")
}
Expand Down Expand Up @@ -360,6 +358,33 @@ func (fs *Decomposedfs) GetUpload(ctx context.Context, id string) (tusd.Upload,
}, nil
}

// lookupNode looks up nodes by path.
// This method can also handle lookups for paths which contain chunking information.
func (fs *Decomposedfs) lookupNode(ctx context.Context, path string) (*node.Node, error) {
p := path
isChunked, err := chunking.IsChunked(path)
if err != nil {
return nil, err
}
if isChunked {
chunkInfo, err := chunking.GetChunkBLOBInfo(path)
if err != nil {
return nil, err
}
p = chunkInfo.Path
}

n, err := fs.lu.NodeFromPath(ctx, p)
if err != nil {
return nil, err
}

if isChunked {
n.Name = filepath.Base(path)
}
return n, nil
}

type fileUpload struct {
// info stores the current information about the upload
info tusd.FileInfo
Expand Down

0 comments on commit 0cc96aa

Please sign in to comment.