From aee90a92475bd09cc0a7f41faeb71f28feaa9097 Mon Sep 17 00:00:00 2001 From: Marius Kleidl Date: Fri, 21 Jun 2024 09:09:28 +0200 Subject: [PATCH] More comments --- pkg/filestore/filestore.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/filestore/filestore.go b/pkg/filestore/filestore.go index 5dd3731f..6f9ab522 100644 --- a/pkg/filestore/filestore.go +++ b/pkg/filestore/filestore.go @@ -60,9 +60,11 @@ func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (ha // The .info file's location can directly be deduced from the upload ID infoPath := store.infoPath(info.ID) // The binary file's location might be modified by the pre-create hook. - binPath := store.binPath(info.ID) + var binPath string if info.Storage != nil && info.Storage["Path"] != "" { binPath = filepath.Join(store.Path, info.Storage["Path"]) + } else { + binPath = store.defaultBinPath(info.ID) } info.Storage = map[string]string{ @@ -104,10 +106,18 @@ func (store FileStore) GetUpload(ctx context.Context, id string) (handler.Upload return nil, err } - binPath := store.binPath(id) + // If the info file contains a custom path to the binary file, we use that. If not, we + // fall back to the default value (although the Path property should always be set in recent + // tusd versions). + var binPath string if info.Storage != nil && info.Storage["Path"] != "" { + // No filepath.Join here because the joining already happened in NewUpload. Duplicate joining + // with relative paths lead to incorrect paths binPath = info.Storage["Path"] + } else { + binPath = store.defaultBinPath(info.ID) } + stat, err := os.Stat(binPath) if err != nil { if os.IsNotExist(err) { @@ -138,8 +148,9 @@ func (store FileStore) AsConcatableUpload(upload handler.Upload) handler.Concata return upload.(*fileUpload) } -// binPath returns the path to the file storing the binary data. -func (store FileStore) binPath(id string) string { +// defaultBinPath returns the path to the file storing the binary data, if it is +// not customized using the pre-create hook. +func (store FileStore) defaultBinPath(id string) string { return filepath.Join(store.Path, id) }