Skip to content

Commit

Permalink
Fix RC6: archive command temporary files aren't removed automatically #…
Browse files Browse the repository at this point in the history
…603 (#604)

* Enhance CacheReader to use user cache directory for temporary files

* Fix RC6: archive command temporary files aren't removed automatically #603
  • Loading branch information
simulot authored Jan 5, 2025
1 parent e96c87c commit 9a5d903
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/cmd/archive/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func run(ctx context.Context, jnl *fileevent.Recorder, _ *app.Application, sourc
} else {
jnl.Record(ctx, fileevent.Written, a)
}
a.Close()
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion internal/fshelper/cachereader/cachereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cachereader
import (
"io"
"os"
"path/filepath"
)

// CacheReader is a reader that caches the data in a temporary file to allow multiple reads
Expand All @@ -20,12 +21,26 @@ func NewCacheReader(rc io.ReadCloser) (*CacheReader, error) {
if f, ok := rc.(*os.File); ok {
c.tmpFile = f
} else {
c.tmpFile, err = os.CreateTemp("", "immich-go_*")
d, err := os.UserCacheDir()
if err != nil {
d = os.TempDir()
}
d = filepath.Join(d, "immich-go", "temp")

err = os.MkdirAll(d, 0o700)
if err != nil {
d = os.TempDir()
}

c.tmpFile, err = os.CreateTemp(d, "immich-go_*")
if err != nil {
return nil, err
}
// be sure to copy the reader content into the temporary file
_, err = io.Copy(c.tmpFile, rc)
if err != nil {
return nil, err
}
rc.Close()
c.shouldRemove = true
}
Expand Down

0 comments on commit 9a5d903

Please sign in to comment.