Skip to content

Commit 6782acf

Browse files
jessegeensglpatcern
authored andcommitted
logs for download / upload / move in localfs
1 parent b3431e8 commit 6782acf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/storage/utils/localfs/localfs.go

+10
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func getUser(ctx context.Context) (*userpb.User, error) {
162162
}
163163

164164
func (fs *localfs) wrap(ctx context.Context, p string) string {
165+
log := appctx.GetLogger(ctx)
165166
// This is to prevent path traversal.
166167
// With this p can't break out of its parent folder
167168
p = path.Join("/", p)
@@ -175,6 +176,7 @@ func (fs *localfs) wrap(ctx context.Context, p string) string {
175176
} else {
176177
internal = path.Join(fs.conf.DataDirectory, p)
177178
}
179+
log.Debug().Str("old", p).Str("wrapped", internal).Msg("localfs: wrap")
178180
return internal
179181
}
180182

@@ -842,6 +844,8 @@ func (fs *localfs) Delete(ctx context.Context, ref *provider.Reference) error {
842844
}
843845

844846
func (fs *localfs) Move(ctx context.Context, oldRef, newRef *provider.Reference) error {
847+
log := appctx.GetLogger(ctx)
848+
log.Debug().Any("from", oldRef).Any("to", newRef).Msg("localfs: move")
845849
oldName, err := fs.resolve(ctx, oldRef)
846850
if err != nil {
847851
return errors.Wrap(err, "localfs: error resolving ref")
@@ -860,6 +864,7 @@ func (fs *localfs) Move(ctx context.Context, oldRef, newRef *provider.Reference)
860864
newName = fs.wrap(ctx, newName)
861865

862866
if err := os.Rename(oldName, newName); err != nil {
867+
log.Error().Err(err).Msg("localfs: error moving " + oldName + " to " + newName)
863868
return errors.Wrap(err, "localfs: error moving "+oldName+" to "+newName)
864869
}
865870

@@ -1062,7 +1067,10 @@ func (fs *localfs) listShareFolderRoot(ctx context.Context, home string, mdKeys
10621067

10631068
func (fs *localfs) Download(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error) {
10641069
fn, err := fs.resolve(ctx, ref)
1070+
log := appctx.GetLogger(ctx)
1071+
10651072
if err != nil {
1073+
log.Error().Err(err).Any("ref", ref).Msg("localfs: error resolving ref")
10661074
return nil, errors.Wrap(err, "localfs: error resolving ref")
10671075
}
10681076

@@ -1074,8 +1082,10 @@ func (fs *localfs) Download(ctx context.Context, ref *provider.Reference) (io.Re
10741082
r, err := os.Open(fn)
10751083
if err != nil {
10761084
if os.IsNotExist(err) {
1085+
log.Error().Err(err).Str("path", fn).Msg("localfs: file not found")
10771086
return nil, errtypes.NotFound(fn)
10781087
}
1088+
log.Error().Err(err).Str("path", fn).Msg("localfs: error opening file")
10791089
return nil, errors.Wrap(err, "localfs: error reading "+fn)
10801090
}
10811091
return r, nil

pkg/storage/utils/localfs/upload.go

+6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import (
4040
var defaultFilePerm = os.FileMode(0664)
4141

4242
func (fs *localfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadCloser, metadata map[string]string) error {
43+
log := appctx.GetLogger(ctx)
4344
upload, err := fs.GetUpload(ctx, ref.GetPath())
45+
log.Info().Any("upload", upload).Msg("localfs: upload")
4446
if err != nil {
4547
return errors.Wrap(err, "localfs: error retrieving upload")
4648
}
@@ -156,6 +158,7 @@ func (fs *localfs) NewUpload(ctx context.Context, info tusd.FileInfo) (upload tu
156158
info.ID = uuid.New().String()
157159

158160
binPath, err := fs.getUploadPath(ctx, info.ID)
161+
log.Info().Str("upload-path", binPath).Err(err).Msg("localfs: got upload path")
159162
if err != nil {
160163
return nil, errors.Wrap(err, "localfs: error resolving upload path")
161164
}
@@ -307,6 +310,7 @@ func (upload *fileUpload) writeInfo() error {
307310

308311
// FinishUpload finishes an upload and moves the file to the internal destination.
309312
func (upload *fileUpload) FinishUpload(ctx context.Context) error {
313+
log := appctx.GetLogger(ctx)
310314
np := upload.info.Storage["InternalDestination"]
311315

312316
// TODO check etag with If-Match header
@@ -318,6 +322,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error {
318322
//}
319323

320324
// if destination exists
325+
log.Info().Str("oldpath", upload.binPath).Str("newpath", np).Msg("localfs: FinishUpload")
321326
if _, err := os.Stat(np); err == nil {
322327
// create revision
323328
if err := upload.fs.archiveRevision(upload.ctx, np); err != nil {
@@ -327,6 +332,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error {
327332

328333
err := os.Rename(upload.binPath, np)
329334
if err != nil {
335+
log.Error().Msg("localfs: Failed to rename in FinishUpload")
330336
return err
331337
}
332338

0 commit comments

Comments
 (0)