Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: make sure open cover and audio files are closed after use
  • Loading branch information
sentriz committed Nov 20, 2021
1 parent e10c8ba commit 1d1ab11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/mockfs/mockfs.go
Expand Up @@ -206,19 +206,23 @@ func (m *MockFS) AddTrack(path string) {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
m.t.Fatalf("mkdir: %v", err)
}
if _, err := os.Create(abspath); err != nil {
f, err := os.Create(abspath)
if err != nil {
m.t.Fatalf("create track: %v", err)
}
defer f.Close()
}

func (m *MockFS) AddCover(path string) {
abspath := filepath.Join(m.dir, path)
if err := os.MkdirAll(filepath.Dir(abspath), os.ModePerm); err != nil {
m.t.Fatalf("mkdir: %v", err)
}
if _, err := os.Create(abspath); err != nil {
f, err := os.Create(abspath)
if err != nil {
m.t.Fatalf("create cover: %v", err)
}
defer f.Close()
}

func (m *MockFS) SetTags(path string, cb func(*Tags)) {
Expand Down
1 change: 1 addition & 0 deletions server/podcasts/podcasts.go
Expand Up @@ -445,6 +445,7 @@ func (p *Podcasts) downloadPodcastCover(podPath string, podcast *db.Podcast) err
if err != nil {
return fmt.Errorf("creating podcast cover: %w", err)
}
defer coverFile.Close()
if _, err := io.Copy(coverFile, resp.Body); err != nil {
return fmt.Errorf("writing podcast cover: %w", err)
}
Expand Down

0 comments on commit 1d1ab11

Please sign in to comment.