StateFile: use file system API, log in UTF-8
This commit is contained in:
parent
3b620112ca
commit
2bb751d9fa
|
@ -243,16 +243,17 @@ glue_state_file_init(GError **error_r)
|
||||||
|
|
||||||
Path path_fs = Path::FromUTF8(path);
|
Path path_fs = Path::FromUTF8(path);
|
||||||
|
|
||||||
g_free(path);
|
|
||||||
|
|
||||||
if (path_fs.IsNull()) {
|
if (path_fs.IsNull()) {
|
||||||
|
g_free(path);
|
||||||
g_set_error(error_r, main_quark(), 0,
|
g_set_error(error_r, main_quark(), 0,
|
||||||
"Failed to convert state file path to FS encoding");
|
"Failed to convert state file path to FS encoding");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
state_file = new StateFile(std::move(path_fs),
|
state_file = new StateFile(std::move(path_fs), path,
|
||||||
*global_partition, *main_loop);
|
*global_partition, *main_loop);
|
||||||
|
g_free(path);
|
||||||
|
|
||||||
state_file->Read();
|
state_file->Read();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,10 @@
|
||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#define G_LOG_DOMAIN "state_file"
|
#define G_LOG_DOMAIN "state_file"
|
||||||
|
|
||||||
StateFile::StateFile(Path &&_path, Partition &_partition, EventLoop &_loop)
|
StateFile::StateFile(Path &&_path, const char *_path_utf8,
|
||||||
:TimeoutMonitor(_loop), path(std::move(_path)), partition(_partition),
|
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_volume_version(0), prev_output_version(0),
|
||||||
prev_playlist_version(0)
|
prev_playlist_version(0)
|
||||||
{
|
{
|
||||||
|
@ -45,12 +47,12 @@ StateFile::StateFile(Path &&_path, Partition &_partition, EventLoop &_loop)
|
||||||
void
|
void
|
||||||
StateFile::Write()
|
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)) {
|
if (G_UNLIKELY(!fp)) {
|
||||||
g_warning("failed to create %s: %s",
|
g_warning("failed to create %s: %s",
|
||||||
path.c_str(), g_strerror(errno));
|
path_utf8.c_str(), g_strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +73,12 @@ StateFile::Read()
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
g_debug("Loading state file %s", path.c_str());
|
g_debug("Loading state file %s", path_utf8.c_str());
|
||||||
|
|
||||||
TextFile file(path);
|
TextFile file(path);
|
||||||
if (file.HasFailed()) {
|
if (file.HasFailed()) {
|
||||||
g_warning("failed to open %s: %s",
|
g_warning("failed to open %s: %s",
|
||||||
path.c_str(), g_strerror(errno));
|
path_utf8.c_str(), g_strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ struct Partition;
|
||||||
|
|
||||||
class StateFile final : private TimeoutMonitor {
|
class StateFile final : private TimeoutMonitor {
|
||||||
Path path;
|
Path path;
|
||||||
|
std::string path_utf8;
|
||||||
|
|
||||||
Partition &partition;
|
Partition &partition;
|
||||||
|
|
||||||
|
@ -41,7 +42,8 @@ class StateFile final : private TimeoutMonitor {
|
||||||
prev_playlist_version;
|
prev_playlist_version;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StateFile(Path &&path, Partition &partition, EventLoop &loop);
|
StateFile(Path &&path, const char *path_utf8,
|
||||||
|
Partition &partition, EventLoop &loop);
|
||||||
|
|
||||||
void Read();
|
void Read();
|
||||||
void Write();
|
void Write();
|
||||||
|
|
Loading…
Reference in New Issue