diff options
author | Max Kellermann <max@musicpd.org> | 2018-07-17 17:01:02 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-07-17 18:33:32 +0200 |
commit | 99d5b616981107f0cb32f9bcc9e29ff92855c78a (patch) | |
tree | 5fbc013510b82fc932d4045ede572774a04edd84 /src/fs | |
parent | 79e89eb23b554248e4b86631109ae551df6c8d48 (diff) |
fs/Path: add operator/(Path,Path)
Modeled after std::filesystem::operator/() from C++17.
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/CheckFile.cxx | 3 | ||||
-rw-r--r-- | src/fs/Path.hxx | 10 | ||||
-rw-r--r-- | src/fs/Path2.cxx | 8 | ||||
-rw-r--r-- | src/fs/StandardDirectory.cxx | 13 |
4 files changed, 23 insertions, 11 deletions
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; } |