aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Main.cxx7
-rw-r--r--src/StateFile.cxx16
-rw-r--r--src/StateFile.hxx4
3 files changed, 16 insertions, 11 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index 7c98c956b..9b6630d60 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -243,16 +243,17 @@ glue_state_file_init(GError **error_r)
Path path_fs = Path::FromUTF8(path);
- g_free(path);
-
if (path_fs.IsNull()) {
+ g_free(path);
g_set_error(error_r, main_quark(), 0,
"Failed to convert state file path to FS encoding");
return false;
}
- state_file = new StateFile(std::move(path_fs),
+ state_file = new StateFile(std::move(path_fs), path,
*global_partition, *main_loop);
+ g_free(path);
+
state_file->Read();
return true;
}
diff --git a/src/StateFile.cxx b/src/StateFile.cxx
index 6f93137a7..a15eb7220 100644
--- a/src/StateFile.cxx
+++ b/src/StateFile.cxx
@@ -34,8 +34,10 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "state_file"
-StateFile::StateFile(Path &&_path, Partition &_partition, EventLoop &_loop)
- :TimeoutMonitor(_loop), path(std::move(_path)), partition(_partition),
+StateFile::StateFile(Path &&_path, const char *_path_utf8,
+ Partition &_partition, EventLoop &_loop)
+ :TimeoutMonitor(_loop), path(std::move(_path)), path_utf8(_path_utf8),
+ partition(_partition),
prev_volume_version(0), prev_output_version(0),
prev_playlist_version(0)
{
@@ -45,12 +47,12 @@ StateFile::StateFile(Path &&_path, Partition &_partition, EventLoop &_loop)
void
StateFile::Write()
{
- g_debug("Saving state file %s", path.c_str());
+ g_debug("Saving state file %s", path_utf8.c_str());
- FILE *fp = fopen(path.c_str(), "w");
+ FILE *fp = FOpen(path, FOpenMode::WriteText);
if (G_UNLIKELY(!fp)) {
g_warning("failed to create %s: %s",
- path.c_str(), g_strerror(errno));
+ path_utf8.c_str(), g_strerror(errno));
return;
}
@@ -71,12 +73,12 @@ StateFile::Read()
{
bool success;
- g_debug("Loading state file %s", path.c_str());
+ g_debug("Loading state file %s", path_utf8.c_str());
TextFile file(path);
if (file.HasFailed()) {
g_warning("failed to open %s: %s",
- path.c_str(), g_strerror(errno));
+ path_utf8.c_str(), g_strerror(errno));
return;
}
diff --git a/src/StateFile.hxx b/src/StateFile.hxx
index bb1c382f4..9ec97d518 100644
--- a/src/StateFile.hxx
+++ b/src/StateFile.hxx
@@ -30,6 +30,7 @@ struct Partition;
class StateFile final : private TimeoutMonitor {
Path path;
+ std::string path_utf8;
Partition &partition;
@@ -41,7 +42,8 @@ class StateFile final : private TimeoutMonitor {
prev_playlist_version;
public:
- StateFile(Path &&path, Partition &partition, EventLoop &loop);
+ StateFile(Path &&path, const char *path_utf8,
+ Partition &partition, EventLoop &loop);
void Read();
void Write();