From abfbd55305587306730d5419b8a3b09e6a43abcb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 17 Oct 2013 21:59:35 +0200 Subject: fs/Path: rename to AllocatedPath The new class Path only holds a string pointer without being responsible for allocation/deallocation. The FileSystem.hxx library accepts Path arguments instead of AllocatedPath, to avoid forcing callers to allocate another string object. --- src/Mapper.cxx | 69 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src/Mapper.cxx') diff --git a/src/Mapper.cxx b/src/Mapper.cxx index 8a6bd2201..e19117feb 100644 --- a/src/Mapper.cxx +++ b/src/Mapper.cxx @@ -25,7 +25,7 @@ #include "Mapper.hxx" #include "Directory.hxx" #include "Song.hxx" -#include "fs/Path.hxx" +#include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" #include "fs/Charset.hxx" #include "fs/FileSystem.hxx" @@ -52,16 +52,16 @@ static size_t music_dir_utf8_length; * The absolute path of the music directory encoded in the filesystem * character set. */ -static Path music_dir_fs = Path::Null(); +static AllocatedPath music_dir_fs = AllocatedPath::Null(); /** * The absolute path of the playlist directory encoded in the * filesystem character set. */ -static Path playlist_dir_fs = Path::Null(); +static AllocatedPath playlist_dir_fs = AllocatedPath::Null(); static void -check_directory(const char *path_utf8, const Path &path_fs) +check_directory(const char *path_utf8, const AllocatedPath &path_fs) { struct stat st; if (!StatFile(path_fs, st)) { @@ -78,7 +78,7 @@ check_directory(const char *path_utf8, const Path &path_fs) } #ifndef WIN32 - const Path x = Path::Build(path_fs, "."); + const auto x = AllocatedPath::Build(path_fs, "."); if (!StatFile(x, st) && errno == EACCES) FormatError(mapper_domain, "No permission to traverse (\"execute\") directory: %s", @@ -92,7 +92,7 @@ check_directory(const char *path_utf8, const Path &path_fs) } static void -mapper_set_music_dir(Path &&path) +mapper_set_music_dir(AllocatedPath &&path) { assert(!path.IsNull()); @@ -106,7 +106,7 @@ mapper_set_music_dir(Path &&path) } static void -mapper_set_playlist_dir(Path &&path) +mapper_set_playlist_dir(AllocatedPath &&path) { assert(!path.IsNull()); @@ -117,7 +117,7 @@ mapper_set_playlist_dir(Path &&path) } void -mapper_init(Path &&_music_dir, Path &&_playlist_dir) +mapper_init(AllocatedPath &&_music_dir, AllocatedPath &&_playlist_dir) { if (!_music_dir.IsNull()) mapper_set_music_dir(std::move(_music_dir)); @@ -136,7 +136,7 @@ mapper_get_music_directory_utf8(void) return music_dir_utf8.c_str(); } -const Path & +const AllocatedPath & mapper_get_music_directory_fs(void) { return music_dir_fs; @@ -153,23 +153,23 @@ map_to_relative_path(const char *path_utf8) : path_utf8; } -Path +AllocatedPath map_uri_fs(const char *uri) { assert(uri != NULL); assert(*uri != '/'); if (music_dir_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); - const Path uri_fs = Path::FromUTF8(uri); + const auto uri_fs = AllocatedPath::FromUTF8(uri); if (uri_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); - return Path::Build(music_dir_fs, uri_fs); + return AllocatedPath::Build(music_dir_fs, uri_fs); } -Path +AllocatedPath map_directory_fs(const Directory *directory) { assert(!music_dir_fs.IsNull()); @@ -180,7 +180,7 @@ map_directory_fs(const Directory *directory) return map_uri_fs(directory->GetPath()); } -Path +AllocatedPath map_directory_child_fs(const Directory *directory, const char *name) { assert(!music_dir_fs.IsNull()); @@ -188,17 +188,17 @@ map_directory_child_fs(const Directory *directory, const char *name) /* check for invalid or unauthorized base names */ if (*name == 0 || strchr(name, '/') != NULL || strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - return Path::Null(); + return AllocatedPath::Null(); - const Path parent_fs = map_directory_fs(directory); + const auto parent_fs = map_directory_fs(directory); if (parent_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); - const Path name_fs = Path::FromUTF8(name); + const auto name_fs = AllocatedPath::FromUTF8(name); if (name_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); - return Path::Build(parent_fs, name_fs); + return AllocatedPath::Build(parent_fs, name_fs); } /** @@ -206,17 +206,17 @@ map_directory_child_fs(const Directory *directory, const char *name) * not have a real parent directory, only the dummy object * #detached_root. */ -static Path +static AllocatedPath map_detached_song_fs(const char *uri_utf8) { - Path uri_fs = Path::FromUTF8(uri_utf8); + auto uri_fs = AllocatedPath::FromUTF8(uri_utf8); if (uri_fs.IsNull()) - return Path::Null(); + return uri_fs; - return Path::Build(music_dir_fs, uri_fs); + return AllocatedPath::Build(music_dir_fs, uri_fs); } -Path +AllocatedPath map_song_fs(const Song *song) { assert(song->IsFile()); @@ -226,7 +226,7 @@ map_song_fs(const Song *song) ? map_detached_song_fs(song->uri) : map_directory_child_fs(song->parent, song->uri); else - return Path::FromUTF8(song->uri); + return AllocatedPath::FromUTF8(song->uri); } std::string @@ -241,24 +241,25 @@ map_fs_to_utf8(const char *path_fs) return PathToUTF8(path_fs); } -const Path & +const AllocatedPath & map_spl_path(void) { return playlist_dir_fs; } -Path +AllocatedPath map_spl_utf8_to_fs(const char *name) { if (playlist_dir_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); std::string filename_utf8 = name; filename_utf8.append(PLAYLIST_FILE_SUFFIX); - const Path filename_fs = Path::FromUTF8(filename_utf8.c_str()); + const auto filename_fs = + AllocatedPath::FromUTF8(filename_utf8.c_str()); if (filename_fs.IsNull()) - return Path::Null(); + return AllocatedPath::Null(); - return Path::Build(playlist_dir_fs, filename_fs); + return AllocatedPath::Build(playlist_dir_fs, filename_fs); } -- cgit v1.2.3