diff options
Diffstat (limited to 'plugins/artwork/lastfm.c')
-rw-r--r-- | plugins/artwork/lastfm.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/plugins/artwork/lastfm.c b/plugins/artwork/lastfm.c index 2aed6d7c..bf76ccca 100644 --- a/plugins/artwork/lastfm.c +++ b/plugins/artwork/lastfm.c @@ -64,9 +64,11 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest) } current_file = fp; - FILE *out = fopen (dest, "w+b"); + char temp[PATH_MAX]; + snprintf (temp, sizeof (temp), "%s.part", dest); + FILE *out = fopen (temp, "w+b"); if (!out) { - trace ("fetch_from_lastfm: failed to open %s for writing\n", dest); + trace ("fetch_from_lastfm: failed to open %s for writing\n", temp); deadbeef->fclose (fp); current_file = NULL; return -1; @@ -88,8 +90,15 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest) deadbeef->fclose (fp); if (error) { + unlink (temp); + return -1; + } + + if (rename (temp, dest) != 0) { + unlink (temp); unlink (dest); return -1; } + return 0; } |