diff options
author | Max Kellermann <max@duempel.org> | 2014-07-30 20:58:14 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-30 22:17:01 +0200 |
commit | 9fb351a139a56fc7b1ece549894f8fc31fa887cd (patch) | |
tree | 7c9ce42a1262af587f1b9fede2b24ff39cef93fc /src/StateFile.cxx | |
parent | 0d0ccacdf3e154b1cc27a0840fce80ac13f9641c (diff) | |
download | mpd-9fb351a139a56fc7b1ece549894f8fc31fa887cd.tar.gz mpd-9fb351a139a56fc7b1ece549894f8fc31fa887cd.tar.xz mpd-9fb351a139a56fc7b1ece549894f8fc31fa887cd.zip |
*Save, *State: use the OutputStream API instead of FILE*
Diffstat (limited to 'src/StateFile.cxx')
-rw-r--r-- | src/StateFile.cxx | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/StateFile.cxx b/src/StateFile.cxx index 0e558f298..e8df1ec0a 100644 --- a/src/StateFile.cxx +++ b/src/StateFile.cxx @@ -22,6 +22,8 @@ #include "output/OutputState.hxx" #include "queue/PlaylistState.hxx" #include "fs/TextFile.hxx" +#include "fs/output/FileOutputStream.hxx" +#include "fs/output/BufferedOutputStream.hxx" #include "Partition.hxx" #include "Instance.hxx" #include "mixer/Volume.hxx" @@ -62,25 +64,35 @@ StateFile::IsModified() const partition.pc); } +inline void +StateFile::Write(BufferedOutputStream &os) +{ + save_sw_volume_state(os); + audio_output_state_save(os, partition.outputs); + playlist_state_save(os, partition.playlist, partition.pc); +} + +inline bool +StateFile::Write(OutputStream &os, Error &error) +{ + BufferedOutputStream bos(os); + Write(bos); + return bos.Flush(error); +} + void StateFile::Write() { FormatDebug(state_file_domain, "Saving state file %s", path_utf8.c_str()); - FILE *fp = FOpen(path, FOpenMode::WriteText); - if (gcc_unlikely(!fp)) { - FormatErrno(state_file_domain, "failed to create %s", - path_utf8.c_str()); + Error error; + FileOutputStream fos(path, error); + if (!fos.IsDefined() || !Write(fos, error) || !fos.Commit(error)) { + LogError(error); return; } - save_sw_volume_state(fp); - audio_output_state_save(fp, partition.outputs); - playlist_state_save(fp, partition.playlist, partition.pc); - - fclose(fp); - RememberVersions(); } |