summaryrefslogtreecommitdiff
path: root/src/PlaylistFile.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max.kellermann@gmail.com>2016-08-15 22:19:55 +0200
committerMax Kellermann <max.kellermann@gmail.com>2016-08-15 22:19:55 +0200
commitb6b8fb7d73173049d9b227eb4991d437cb129a37 (patch)
tree6c71e00d449d5aa30918e3f7363124d8cceae895 /src/PlaylistFile.cxx
parent2bca3cd24746a3dd365f1478b185160fe84b5033 (diff)
PlaylistFile: use TruncateFile()
As a side effect, "playlistclear" no longer creates a new playlist if the given one doesn't yet exist.
Diffstat (limited to 'src/PlaylistFile.cxx')
-rw-r--r--src/PlaylistFile.cxx14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index dbd1a22c5..0afebba32 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -302,11 +302,15 @@ spl_clear(const char *utf8path)
const auto path_fs = spl_map_to_fs(utf8path);
assert(!path_fs.IsNull());
- FILE *file = FOpen(path_fs, FOpenMode::WriteText);
- if (file == nullptr)
- ThrowPlaylistErrno();
-
- fclose(file);
+ try {
+ TruncateFile(path_fs);
+ } catch (const std::system_error &e) {
+ if (IsFileNotFound(e))
+ throw PlaylistError(PlaylistResult::NO_SUCH_LIST,
+ "No such playlist");
+ else
+ throw;
+ }
idle_add(IDLE_STORED_PLAYLIST);
}