Skip to content

Commit e709259

Browse files
authored
fix: properly cleanup temporary directory (italia#246)
Properly cleanup the downloaded file and its temp directory when running checks for image formats.
1 parent 025d6ff commit e709259

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

validations.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,17 @@ func (p *Parser) validLogo(u url.URL, network bool) (bool, error) {
180180
}
181181

182182
defer func() {
183-
file := path.Dir(localPath)
184-
if err := os.Remove(file); err != nil {
185-
fmt.Fprintf(os.Stderr, "failed to remove %s: %v\n", file, err)
183+
if localPath == "" {
184+
return
185+
}
186+
187+
if err := os.Remove(localPath); err != nil {
188+
fmt.Fprintf(os.Stderr, "failed to remove %s: %v\n", localPath, err)
189+
}
190+
191+
dir := path.Dir(localPath)
192+
if err = os.Remove(dir); err != nil {
193+
fmt.Fprintf(os.Stderr, "failed to remove %s: %v\n", dir, err)
186194
}
187195
}()
188196
} else {

0 commit comments

Comments
 (0)