fs/Path: add operator/(Path,Path)
Modeled after std::filesystem::operator/() from C++17.
This commit is contained in:
@@ -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))
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user