Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
[cbox-commit-20] Fix cephfs namespace and zero-size file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Feb 28, 2022
1 parent 85f508d commit 42edcc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
7 changes: 7 additions & 0 deletions pkg/storage/fs/cephfs/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ func (fs *cephfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKey
return
}

// The user wants to access their home, create it if it doesn't exist
if path == user.home {
if err = fs.CreateHome(ctx); err != nil {
return
}
}

user.op(func(cv *cacheVal) {
var dir *cephfs2.Directory
if dir, err = cv.mount.OpenDir(path); err != nil {
Expand Down
17 changes: 1 addition & 16 deletions pkg/storage/fs/cephfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ func (fs *cephfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read
user := fs.makeUser(ctx)
upload, err := fs.GetUpload(ctx, ref.GetPath())
if err != nil {
metadata := map[string]string{"sizedeferred": "true"}
uploadIDs, err := fs.InitiateUpload(ctx, ref, 0, metadata)
if err != nil {
return err
}
if upload, err = fs.GetUpload(ctx, uploadIDs["simple"]); err != nil {
return errors.Wrap(err, "cephfs: error retrieving upload")
}
return errors.Wrap(err, "cephfs: error retrieving upload")
}

uploadInfo := upload.(*fileUpload)
Expand Down Expand Up @@ -197,14 +190,6 @@ func (fs *cephfs) NewUpload(ctx context.Context, info tusd.FileInfo) (upload tus
ctx: ctx,
}

if !info.SizeIsDeferred && info.Size == 0 {
log.Debug().Interface("info", info).Msg("cephfs: finishing upload for empty file")
// no need to create info file and finish directly
err = upload.FinishUpload(ctx)

return
}

// writeInfo creates the file by itself if necessary
err = upload.(*fileUpload).writeInfo()

Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/fs/cephfs/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cephfs
import (
"context"
"fmt"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -216,7 +217,7 @@ func (user *User) fileAsResourceInfo(cv *cacheVal, path string, stat *cephfs2.Ce
Etag: etag,
MimeType: mime.Detect(isDir(_type), path),
Mtime: mtime,
Path: path,
Path: strings.TrimPrefix(path, user.home),
PermissionSet: perms,
Size: size,
Owner: ownerID,
Expand All @@ -236,7 +237,6 @@ func (user *User) resolveRef(ref *provider.Reference) (str string, err error) {
return "", errtypes.NotSupported("cephfs: entry IDs not currently supported")
}

str = removeLeadingSlash(str) //path must be relative

str = path.Join(user.home, str)
return
}

0 comments on commit 42edcc2

Please sign in to comment.