Skip to content

Commit

Permalink
More comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Jun 21, 2024
1 parent c79c0d0 commit aee90a9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/filestore/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit aee90a9

Please sign in to comment.