summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-17 17:01:02 +0200
committerMax Kellermann <max@musicpd.org>2018-07-17 18:33:32 +0200
commit99d5b616981107f0cb32f9bcc9e29ff92855c78a (patch)
tree5fbc013510b82fc932d4045ede572774a04edd84
parent79e89eb23b554248e4b86631109ae551df6c8d48 (diff)
fs/Path: add operator/(Path,Path)
Modeled after std::filesystem::operator/() from C++17.
-rw-r--r--src/CommandLine.cxx2
-rw-r--r--src/Main.cxx4
-rw-r--r--src/Mapper.cxx4
-rw-r--r--src/PlaylistFile.cxx2
-rw-r--r--src/command/FileCommands.cxx3
-rw-r--r--src/config/Path.cxx2
-rw-r--r--src/db/Configured.cxx3
-rw-r--r--src/db/plugins/simple/SimpleDatabasePlugin.cxx3
-rw-r--r--src/db/update/InotifyUpdate.cxx10
-rw-r--r--src/fs/CheckFile.cxx3
-rw-r--r--src/fs/Path.hxx10
-rw-r--r--src/fs/Path2.cxx8
-rw-r--r--src/fs/StandardDirectory.cxx13
-rw-r--r--src/storage/plugins/LocalStorage.cxx5
14 files changed, 40 insertions, 32 deletions
diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx
index ecfae241e..f1d6d0020 100644
--- a/src/CommandLine.cxx
+++ b/src/CommandLine.cxx
@@ -310,7 +310,7 @@ bool ConfigLoader::TryFile(const AllocatedPath &base_path, Path path)
{
if (base_path.IsNull())
return false;
- auto full_path = AllocatedPath::Build(base_path, path);
+ auto full_path = base_path / path;
return TryFile(full_path);
}
diff --git a/src/Main.cxx b/src/Main.cxx
index a489c652a..536f2ac90 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -260,7 +260,7 @@ glue_state_file_init()
if (cache_dir.IsNull())
return;
- path_fs = AllocatedPath::Build(cache_dir, "state");
+ path_fs = cache_dir / Path::FromFS("state");
#else
return;
#endif
@@ -486,7 +486,7 @@ try {
const auto sdcard = Environment::getExternalStorageDirectory();
if (!sdcard.IsNull()) {
const auto config_path =
- AllocatedPath::Build(sdcard, "mpd.conf");
+ sdcard / Path::FromFS("mpd.conf");
if (FileExists(config_path))
ReadConfigFile(config_path);
}
diff --git a/src/Mapper.cxx b/src/Mapper.cxx
index 089469ea3..bb0387060 100644
--- a/src/Mapper.cxx
+++ b/src/Mapper.cxx
@@ -82,7 +82,7 @@ map_uri_fs(const char *uri) noexcept
if (uri_fs.IsNull())
return nullptr;
- return AllocatedPath::Build(music_dir_fs, uri_fs);
+ return music_dir_fs / uri_fs;
}
std::string
@@ -128,5 +128,5 @@ map_spl_utf8_to_fs(const char *name) noexcept
if (filename_fs.IsNull())
return nullptr;
- return AllocatedPath::Build(playlist_dir_fs, filename_fs);
+ return playlist_dir_fs / filename_fs;
}
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index 101e9ecec..a1b83eb41 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -138,7 +138,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
return false;
FileInfo fi;
- if (!GetFileInfo(AllocatedPath::Build(parent_path_fs, name_fs), fi) ||
+ if (!GetFileInfo(parent_path_fs / name_fs, fi) ||
!fi.IsRegular())
return false;
diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx
index c6b54cee8..8a2167789 100644
--- a/src/command/FileCommands.cxx
+++ b/src/command/FileCommands.cxx
@@ -81,8 +81,7 @@ handle_listfiles_local(Response &r, Path path_fs)
if (name_utf8.empty())
continue;
- const AllocatedPath full_fs =
- AllocatedPath::Build(path_fs, name_fs);
+ const auto full_fs = path_fs / name_fs;
FileInfo fi;
if (!GetFileInfo(full_fs, fi, false))
continue;
diff --git a/src/config/Path.cxx b/src/config/Path.cxx
index 32d23c9df..e5e4256ae 100644
--- a/src/config/Path.cxx
+++ b/src/config/Path.cxx
@@ -113,7 +113,7 @@ ParsePath(const char *path)
if (path2.IsNull())
return nullptr;
- return AllocatedPath::Build(home, path2);
+ return home / path2;
} else if (!PathTraitsUTF8::IsAbsolute(path)) {
throw FormatRuntimeError("not an absolute path: %s", path);
} else {
diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx
index 79b28197b..fc0c7d5dd 100644
--- a/src/db/Configured.cxx
+++ b/src/db/Configured.cxx
@@ -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;
diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
index 6ea2bf9bd..94510110c 100644
--- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
@@ -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();
diff --git a/src/db/update/InotifyUpdate.cxx b/src/db/update/InotifyUpdate.cxx
index e1a1e9dbd..d0ea2daec 100644
--- a/src/db/update/InotifyUpdate.cxx
+++ b/src/db/update/InotifyUpdate.cxx
@@ -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());
diff --git a/src/fs/CheckFile.cxx b/src/fs/CheckFile.cxx
index 67578e182..189aabfe6 100644
--- a/src/fs/CheckFile.cxx
+++ b/src/fs/CheckFile.cxx
@@ -43,8 +43,7 @@ try {
#ifndef _WIN32
try {
- const auto x = AllocatedPath::Build(path_fs,
- PathTraitsFS::CURRENT_DIRECTORY);
+ const auto x = path_fs / Path::FromFS(PathTraitsFS::CURRENT_DIRECTORY);
const FileInfo fi2(x);
} catch (const std::system_error &e) {
if (IsAccessDenied(e))
diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx
index 2e7393eab..2415923d0 100644
--- a/src/fs/Path.hxx
+++ b/src/fs/Path.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2017 The Music Player Daemon Project
+ * Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -169,4 +169,12 @@ public:
const_pointer_type GetSuffix() const noexcept;
};
+/**
+ * Concatenate two path components using the directory separator.
+ *
+ * Wrapper for AllocatedPath::Build().
+ */
+AllocatedPath
+operator/(Path a, Path b) noexcept;
+
#endif
diff --git a/src/fs/Path2.cxx b/src/fs/Path2.cxx
index 44410f9a2..f5f0662cf 100644
--- a/src/fs/Path2.cxx
+++ b/src/fs/Path2.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2017 The Music Player Daemon Project
+ * Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -26,3 +26,9 @@ Path::GetDirectoryName() const noexcept
{
return AllocatedPath::FromFS(PathTraitsFS::GetParent(c_str()));
}
+
+AllocatedPath
+operator/(Path a, Path b) noexcept
+{
+ return AllocatedPath::Build(a, b);
+}
diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx
index 67845e39b..65d6b7a1c 100644
--- a/src/fs/StandardDirectory.cxx
+++ b/src/fs/StandardDirectory.cxx
@@ -183,16 +183,16 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir)
*line_end = 0;
// build the result path
- const char *path = line;
+ const auto path_fs = Path::FromFS(line);
AllocatedPath result = nullptr;
if (home_relative) {
auto home = GetHomeDir();
if (home.IsNull())
return true;
- result = AllocatedPath::Build(home, path);
+ result = home / path_fs;
} else {
- result = AllocatedPath::FromFS(path);
+ result = AllocatedPath(path_fs);
}
if (IsValidDir(result.c_str())) {
@@ -209,9 +209,8 @@ try {
auto config_dir = GetUserConfigDir();
if (config_dir.IsNull())
return result;
- auto dirs_file = AllocatedPath::Build(config_dir, "user-dirs.dirs");
- TextFile input(dirs_file);
+ TextFile input(config_dir / Path::FromFS("user-dirs.dirs"));
char *line;
while ((line = input.ReadLine()) != nullptr)
if (ParseConfigLine(line, name, result))
@@ -237,7 +236,7 @@ GetUserConfigDir() noexcept
// Check for $HOME/.config
auto home = GetHomeDir();
if (!home.IsNull()) {
- AllocatedPath fallback = AllocatedPath::Build(home, ".config");
+ auto fallback = home / Path::FromFS(".config");
if (IsValidDir(fallback.c_str()))
return fallback;
}
@@ -274,7 +273,7 @@ GetUserCacheDir() noexcept
// Check for $HOME/.cache
auto home = GetHomeDir();
if (!home.IsNull()) {
- AllocatedPath fallback = AllocatedPath::Build(home, ".cache");
+ auto fallback = home / Path::FromFS(".cache");
if (IsValidDir(fallback.c_str()))
return fallback;
}
diff --git a/src/storage/plugins/LocalStorage.cxx b/src/storage/plugins/LocalStorage.cxx
index 83b877648..78e5df2e4 100644
--- a/src/storage/plugins/LocalStorage.cxx
+++ b/src/storage/plugins/LocalStorage.cxx
@@ -114,8 +114,7 @@ LocalStorage::MapFSOrThrow(const char *uri_utf8) const
if (StringIsEmpty(uri_utf8))
return base_fs;
- return AllocatedPath::Build(base_fs,
- AllocatedPath::FromUTF8Throw(uri_utf8));
+ return base_fs / AllocatedPath::FromUTF8Throw(uri_utf8);
}
AllocatedPath
@@ -176,7 +175,7 @@ LocalDirectoryReader::Read() noexcept
StorageFileInfo
LocalDirectoryReader::GetInfo(bool follow)
{
- return Stat(AllocatedPath::Build(base_fs, reader.GetEntry()), follow);
+ return Stat(base_fs / reader.GetEntry(), follow);
}
std::unique_ptr<Storage>