Skip to content

Commit 3cc8ccf

Browse files
committed
Correctly closes temporary files in cache
1 parent b405e05 commit 3cc8ccf

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/cache/cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func CacheToFile(cacheFolderName string, filename string, reader io.ReadCloser)
104104
}
105105
}
106106

107+
// Close file as it's not needed anymore. Without closing it, Windows has problems moving the file.
108+
err = tempFile.Close()
109+
if err != nil {
110+
return errors.Wrap(err, fmt.Sprintf("Unable to close temporary file '%s'", filepath.Join(GetTempPath(), filename)))
111+
}
112+
107113
//
108114
// 3. Move file to actual location
109115
//

src/util/files.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type FileLike interface {
137137
Name() string
138138
Write(p []byte) (n int, err error)
139139
Stat() (os.FileInfo, error)
140+
Close() error
140141
}
141142

142143
type Filesystem interface {

src/util/files_mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func (m *MockFile) Stat() (os.FileInfo, error) {
7070
return NewMockFileInfo(m.Name()), nil
7171
}
7272

73+
func (m *MockFile) Close() error {
74+
return nil
75+
}
76+
7377
type MockFilesystem struct {
7478
ExistsFunc func(path string) bool
7579
GetSizeInBytesFunc func(path string) (int64, error)

0 commit comments

Comments
 (0)