diff options
author | Denis Krjuchkov <denis@crazydev.net> | 2013-01-27 13:26:17 +0600 |
---|---|---|
committer | Denis Krjuchkov <denis@crazydev.net> | 2013-01-28 00:13:46 +0600 |
commit | e98e2a0b07363132707146f571d3411e3e1b8076 (patch) | |
tree | ce4653efde5670ca2a151e2888114ac9c0423fe4 /src/Mapper.cxx | |
parent | 943064bb5148884339ccaf60e276191bc4d9abd9 (diff) | |
download | mpd-e98e2a0b07363132707146f571d3411e3e1b8076.tar.gz mpd-e98e2a0b07363132707146f571d3411e3e1b8076.tar.xz mpd-e98e2a0b07363132707146f571d3411e3e1b8076.zip |
Path::FromUTF8() returns nulled instance on error, add error handling where required
Diffstat (limited to 'src/Mapper.cxx')
-rw-r--r-- | src/Mapper.cxx | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/Mapper.cxx b/src/Mapper.cxx index fa5af2dba..559df0d23 100644 --- a/src/Mapper.cxx +++ b/src/Mapper.cxx @@ -57,6 +57,12 @@ static size_t music_dir_fs_length; */ static Path playlist_dir_fs = Path::Null(); +static inline GQuark +mapper_quark() +{ + return g_quark_from_static_string ("mapper"); +} + /** * Duplicate a string, chop all trailing slashes. */ @@ -98,31 +104,52 @@ check_directory(const char *path_utf8, const Path &path_fs) g_warning("No permission to read directory: %s", path_utf8); } -static void -mapper_set_music_dir(const char *path_utf8) +static bool +mapper_set_music_dir(const char *path_utf8, GError **error_r) { + music_dir_fs = Path::FromUTF8(path_utf8); + if (music_dir_fs.IsNull()) { + g_set_error(error_r, mapper_quark(), 0, + "Failed to convert music path to FS encoding"); + return false; + } + + music_dir_fs_length = music_dir_fs.length(); + music_dir_utf8 = strdup_chop_slash(path_utf8); music_dir_utf8_length = strlen(music_dir_utf8); - music_dir_fs = Path::FromUTF8(path_utf8); check_directory(path_utf8, music_dir_fs); - music_dir_fs_length = music_dir_fs.length(); + + return true; } -static void -mapper_set_playlist_dir(const char *path_utf8) +static bool +mapper_set_playlist_dir(const char *path_utf8, GError **error_r) { playlist_dir_fs = Path::FromUTF8(path_utf8); + if (playlist_dir_fs.IsNull()) { + g_set_error(error_r, mapper_quark(), 0, + "Failed to convert playlist path to FS encoding"); + return false; + } + check_directory(path_utf8, playlist_dir_fs); + return true; } -void mapper_init(const char *_music_dir, const char *_playlist_dir) +bool mapper_init(const char *_music_dir, const char *_playlist_dir, + GError **error_r) { if (_music_dir != NULL) - mapper_set_music_dir(_music_dir); + if (!mapper_set_music_dir(_music_dir, error_r)) + return false; if (_playlist_dir != NULL) - mapper_set_playlist_dir(_playlist_dir); + if (!mapper_set_playlist_dir(_playlist_dir, error_r)) + return false; + + return true; } void mapper_finish(void) |