summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/PlaylistFile.cxx10
-rw-r--r--src/PlaylistSave.cxx4
-rw-r--r--src/StateFile.cxx4
-rw-r--r--src/db/plugins/simple/SimpleDatabasePlugin.cxx3
-rw-r--r--src/fs/io/FileOutputStream.cxx44
-rw-r--r--src/fs/io/FileOutputStream.hxx4
-rw-r--r--src/output/plugins/RecorderOutputPlugin.cxx30
-rw-r--r--test/WriteFile.cxx6
8 files changed, 61 insertions, 44 deletions
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index 259c26974..c90af9760 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -239,7 +239,11 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
for (const auto &uri_utf8 : contents)
playlist_print_uri(bos, uri_utf8.c_str());
- return bos.Flush(error) && fos.Commit(error);
+ if (!bos.Flush(error))
+ return false;
+
+ fos.Commit();
+ return true;
}
PlaylistFileContents
@@ -411,9 +415,11 @@ spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
playlist_print_song(bos, song);
- if (!bos.Flush(error) || !fos.Commit(error))
+ if (!bos.Flush(error))
return false;
+ fos.Commit();
+
idle_add(IDLE_STORED_PLAYLIST);
return true;
}
diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx
index 8d822ce8f..d83ceb2b7 100644
--- a/src/PlaylistSave.cxx
+++ b/src/PlaylistSave.cxx
@@ -86,9 +86,11 @@ spl_save_queue(const char *name_utf8, const Queue &queue, Error &error)
for (unsigned i = 0; i < queue.GetLength(); i++)
playlist_print_song(bos, queue.Get(i));
- if (!bos.Flush(error) || !fos.Commit(error))
+ if (!bos.Flush(error))
return false;
+ fos.Commit();
+
idle_add(IDLE_STORED_PLAYLIST);
return true;
}
diff --git a/src/StateFile.cxx b/src/StateFile.cxx
index 8d17a1827..7c92ae0ee 100644
--- a/src/StateFile.cxx
+++ b/src/StateFile.cxx
@@ -92,10 +92,12 @@ StateFile::Write()
try {
Error error;
FileOutputStream fos(path);
- if (!Write(fos, error) || !fos.Commit(error)) {
+ if (!Write(fos, error)) {
LogError(error);
return;
}
+
+ fos.Commit();
} catch (const std::exception &e) {
LogError(e);
}
diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
index 8538ca502..97e2e6c2b 100644
--- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
@@ -411,8 +411,7 @@ SimpleDatabase::Save(Error &error)
}
#endif
- if (!fos.Commit(error))
- return false;
+ fos.Commit();
FileInfo fi;
if (GetFileInfo(path, fi))
diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx
index bf23cafc1..d0b1edd56 100644
--- a/src/fs/io/FileOutputStream.cxx
+++ b/src/fs/io/FileOutputStream.cxx
@@ -72,13 +72,12 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return true;
}
-bool
-FileOutputStream::Commit(gcc_unused Error &error)
+void
+FileOutputStream::Commit()
{
assert(IsDefined());
Close();
- return true;
}
void
@@ -162,8 +161,8 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return true;
}
-bool
-FileOutputStream::Commit(Error &error)
+void
+FileOutputStream::Commit()
{
assert(IsDefined());
@@ -176,20 +175,20 @@ FileOutputStream::Commit(Error &error)
snprintf(fd_path, sizeof(fd_path), "/proc/self/fd/%d",
GetFD().Get());
if (linkat(AT_FDCWD, fd_path, AT_FDCWD, GetPath().c_str(),
- AT_SYMLINK_FOLLOW) < 0) {
- error.FormatErrno("Failed to commit %s",
+ AT_SYMLINK_FOLLOW) < 0)
+ throw FormatErrno("Failed to commit %s",
GetPath().c_str());
- Close();
- return false;
- }
}
#endif
- bool success = Close();
- if (!success)
- error.FormatErrno("Failed to commit %s", GetPath().c_str());
-
- return success;
+ if (!Close()) {
+#ifdef WIN32
+ throw FormatLastError("Failed to commit %s",
+ GetPath().ToUTF8().c_str());
+#else
+ throw FormatErrno("Failed to commit %s", GetPath().c_str());
+#endif
+ }
}
void
@@ -233,18 +232,17 @@ AppendFileOutputStream::AppendFileOutputStream(Path _path)
#endif
}
-bool
-AppendFileOutputStream::Commit(gcc_unused Error &error)
+void
+AppendFileOutputStream::Commit()
{
assert(IsDefined());
+ if (!Close()) {
#ifdef WIN32
- return Close();
+ throw FormatLastError("Failed to commit %s",
+ GetPath().ToUTF8().c_str());
#else
- bool success = Close();
- if (!success)
- error.FormatErrno("Failed to commit %s", GetPath().c_str());
-
- return success;
+ throw FormatErrno("Failed to commit %s", GetPath().c_str());
#endif
+ }
}
diff --git a/src/fs/io/FileOutputStream.hxx b/src/fs/io/FileOutputStream.hxx
index ec83aa615..0cf8bfc4d 100644
--- a/src/fs/io/FileOutputStream.hxx
+++ b/src/fs/io/FileOutputStream.hxx
@@ -139,7 +139,7 @@ public:
Cancel();
}
- bool Commit(Error &error);
+ void Commit();
void Cancel();
};
@@ -152,7 +152,7 @@ public:
Close();
}
- bool Commit(Error &error);
+ void Commit();
};
#endif
diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx
index ee1c5ef63..562e36f87 100644
--- a/src/output/plugins/RecorderOutputPlugin.cxx
+++ b/src/output/plugins/RecorderOutputPlugin.cxx
@@ -244,8 +244,14 @@ RecorderOutput::Commit(Error &error)
encoder->Close();
- if (success && !file->Commit(error))
- success = false;
+ if (success) {
+ try {
+ file->Commit();
+ } catch (...) {
+ delete file;
+ throw;
+ }
+ }
delete file;
@@ -263,9 +269,13 @@ RecorderOutput::Close()
return;
}
- Error error;
- if (!Commit(error))
- LogError(error);
+ try {
+ Error error;
+ if (!Commit(error))
+ LogError(error);
+ } catch (const std::exception &e) {
+ LogError(e);
+ }
if (HasDynamicPath()) {
assert(!path.IsNull());
@@ -281,9 +291,13 @@ RecorderOutput::FinishFormat()
if (file == nullptr)
return;
- Error error;
- if (!Commit(error))
- LogError(error);
+ try {
+ Error error;
+ if (!Commit(error))
+ LogError(error);
+ } catch (const std::exception &e) {
+ LogError(e);
+ }
file = nullptr;
path.SetNull();
diff --git a/test/WriteFile.cxx b/test/WriteFile.cxx
index 1366323c7..e762a9aa5 100644
--- a/test/WriteFile.cxx
+++ b/test/WriteFile.cxx
@@ -61,16 +61,12 @@ main(int argc, char **argv)
const Path path = Path::FromFS(argv[1]);
try {
- Error error;
FileOutputStream fos(path);
if (!Copy(fos, STDIN_FILENO))
return EXIT_FAILURE;
- if (!fos.Commit(error)) {
- fprintf(stderr, "%s\n", error.GetMessage());
- return EXIT_FAILURE;
- }
+ fos.Commit();
return EXIT_SUCCESS;
} catch (const std::exception &e) {