diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-05-22 12:12:19 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-05-22 12:12:19 +0200 |
commit | cacfeb0d9749074f6fd58fb58db3e8dcf7a2a139 (patch) | |
tree | 5a6e9f8c4fb6bbd9a7a28d6cd0f846bfafbd6b8a /plugins/artwork/albumartorg.c | |
parent | c2ec43487c376f5e44db0b7513675c8788869f95 (diff) |
coverart: prevent attempts to load partial files
Diffstat (limited to 'plugins/artwork/albumartorg.c')
-rw-r--r-- | plugins/artwork/albumartorg.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/plugins/artwork/albumartorg.c b/plugins/artwork/albumartorg.c index 18b494a4..d438cf9c 100644 --- a/plugins/artwork/albumartorg.c +++ b/plugins/artwork/albumartorg.c @@ -74,9 +74,11 @@ fetch_from_albumart_org (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_albumart_org: failed to open %s for writing\n", dest); + trace ("fetch_from_albumart_org: failed to open %s for writing\n", temp); current_file = NULL; deadbeef->fclose (fp); return -1; @@ -98,9 +100,16 @@ fetch_from_albumart_org (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; } |