fs/io/BufferedReader: new class to replace class TextFile
The new class is pluggable, to prepare for gzipped database files. For now, the TextFile class remains, and will be refactored away later.
This commit is contained in:
@@ -116,6 +116,29 @@ spl_map_to_fs(const char *name_utf8, Error &error)
|
||||
return path_fs;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static bool
|
||||
IsNotFoundError(const Error &error)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return error.IsDomain(win32_domain) &&
|
||||
error.GetCode() == ERROR_FILE_NOT_FOUND;
|
||||
#else
|
||||
return error.IsDomain(errno_domain) &&
|
||||
error.GetCode() == ENOENT;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
TranslatePlaylistError(Error &error)
|
||||
{
|
||||
if (IsNotFoundError(error)) {
|
||||
error.Clear();
|
||||
error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST),
|
||||
"No such playlist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an #Error for the current errno.
|
||||
*/
|
||||
@@ -228,9 +251,9 @@ LoadPlaylistFile(const char *utf8path, Error &error)
|
||||
if (path_fs.IsNull())
|
||||
return contents;
|
||||
|
||||
TextFile file(path_fs);
|
||||
TextFile file(path_fs, error);
|
||||
if (file.HasFailed()) {
|
||||
playlist_errno(error);
|
||||
TranslatePlaylistError(error);
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user