fs/Path: add operator/(Path,Path)

Modeled after std::filesystem::operator/() from C++17.
This commit is contained in:
Max Kellermann
2018-07-17 17:01:02 +02:00
parent 79e89eb23b
commit 99d5b61698
14 changed files with 40 additions and 32 deletions

View File

@@ -53,8 +53,7 @@ CreateConfiguredDatabase(EventLoop &main_event_loop, EventLoop &io_event_loop,
if (cache_dir.IsNull())
return nullptr;
const auto db_file = AllocatedPath::Build(cache_dir,
PATH_LITERAL("mpd.db"));
const auto db_file = cache_dir / Path::FromFS(PATH_LITERAL("mpd.db"));
const auto db_file_utf8 = db_file.ToUTF8();
if (db_file_utf8.empty())
return nullptr;

View File

@@ -428,8 +428,7 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri)
#ifndef ENABLE_ZLIB
constexpr bool compress = false;
#endif
auto db = new SimpleDatabase(AllocatedPath::Build(cache_path,
name_fs.c_str()),
auto db = new SimpleDatabase(cache_path / name_fs,
compress);
try {
db->Open();

View File

@@ -141,7 +141,7 @@ WatchDirectory::GetUriFS() const noexcept
if (uri.IsNull())
return name;
return AllocatedPath::Build(uri, name);
return uri / name;
}
/* we don't look at "." / ".." nor files with newlines in their name */
@@ -181,8 +181,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
if (skip_path(ent->d_name))
continue;
const auto child_path_fs =
AllocatedPath::Build(path_fs, ent->d_name);
const auto name_fs = Path::FromFS(ent->d_name);
const auto child_path_fs = path_fs / name_fs;
FileInfo fi;
try {
@@ -211,7 +211,7 @@ recursive_watch_subdirectories(WatchDirectory *directory,
continue;
directory->children.emplace_front(directory,
AllocatedPath::FromFS(ent->d_name),
name_fs,
ret);
child = &directory->children.front();
@@ -262,7 +262,7 @@ mpd_inotify_callback(int wd, unsigned mask,
const auto path_fs = uri_fs.IsNull()
? root
: AllocatedPath::Build(root, uri_fs.c_str());
: (root / uri_fs);
recursive_watch_subdirectories(directory, path_fs,
directory->GetDepth());