From e06e73f93605b61383726ff30207df6029ddb489 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Wed, 13 Nov 2024 18:07:01 +0000 Subject: [PATCH 1/2] moved from fdb --- src/eckit/filesystem/LocalPathName.cc | 12 ++++++++++++ src/eckit/filesystem/LocalPathName.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/eckit/filesystem/LocalPathName.cc b/src/eckit/filesystem/LocalPathName.cc index 980e62872..7b2c9c804 100644 --- a/src/eckit/filesystem/LocalPathName.cc +++ b/src/eckit/filesystem/LocalPathName.cc @@ -415,6 +415,18 @@ void operator>>(Stream& s, LocalPathName& path) { s >> path.path_; } +LocalPathName operator/(const LocalPathName& p1, const LocalPathName& p2) { + bool tildeIsUserHome = false; + bool skipTildeExpansion = true; + return eckit::LocalPathName(p1.path() + "/" + p2.path(), tildeIsUserHome, skipTildeExpansion); +} + +LocalPathName operator/(const LocalPathName& p1, const char* p2) { + bool tildeIsUserHome = false; + bool skipTildeExpansion = true; + return eckit::LocalPathName(p1.path() + "/" + p2, tildeIsUserHome, skipTildeExpansion); +} + LocalPathName LocalPathName::fullName() const { if (path_.length() > 0 && path_[0] != '/') { char buf[PATH_MAX]; diff --git a/src/eckit/filesystem/LocalPathName.h b/src/eckit/filesystem/LocalPathName.h index 4cd9b61a6..a9ad35231 100644 --- a/src/eckit/filesystem/LocalPathName.h +++ b/src/eckit/filesystem/LocalPathName.h @@ -54,6 +54,8 @@ class LocalPathName { tidy(tildeIsUserHome, skipTildeExpansion); } } + explicit LocalPathName(const eckit::PathName& path) : + LocalPathName(path.path(), false, true) {} LocalPathName(const LocalPathName& p) : path_(p.path_) {} @@ -279,6 +281,10 @@ class LocalPathName { friend LocalPathName operator+(const LocalPathName& p, const char* s) { return LocalPathName(p.path_ + s); } friend LocalPathName operator+(const LocalPathName& p, char s) { return LocalPathName(p.path_ + s); } + + friend LocalPathName operator/(const LocalPathName& p1, const LocalPathName& p2); + + friend LocalPathName operator/(const LocalPathName& p1, const char* p2); }; template <> From c74365f239ae35b6a2e2cd02f60dd3c2f5118efe Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Wed, 13 Nov 2024 18:15:41 +0000 Subject: [PATCH 2/2] fix include PathName --- src/eckit/filesystem/LocalPathName.cc | 4 ++++ src/eckit/filesystem/LocalPathName.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/eckit/filesystem/LocalPathName.cc b/src/eckit/filesystem/LocalPathName.cc index 7b2c9c804..64ca6de0b 100644 --- a/src/eckit/filesystem/LocalPathName.cc +++ b/src/eckit/filesystem/LocalPathName.cc @@ -29,6 +29,7 @@ #include "eckit/config/LibEcKit.h" #include "eckit/config/Resource.h" #include "eckit/filesystem/BasePathNameT.h" +#include "eckit/filesystem/PathName.h" #include "eckit/filesystem/PathNameFactory.h" #include "eckit/filesystem/StdDir.h" #include "eckit/io/FileHandle.h" @@ -149,6 +150,9 @@ static void init() { //---------------------------------------------------------------------------------------------------------------------- +LocalPathName::LocalPathName(const PathName& path) : + LocalPathName(path.path(), false, true) {} + LocalPathName LocalPathName::baseName(bool ext) const { const char* q = path_.c_str(); int n = -1; diff --git a/src/eckit/filesystem/LocalPathName.h b/src/eckit/filesystem/LocalPathName.h index a9ad35231..079a2b4a0 100644 --- a/src/eckit/filesystem/LocalPathName.h +++ b/src/eckit/filesystem/LocalPathName.h @@ -29,6 +29,7 @@ namespace eckit { class Length; class DataHandle; class BasePathName; +class PathName; struct FileSystemSize; @@ -54,8 +55,7 @@ class LocalPathName { tidy(tildeIsUserHome, skipTildeExpansion); } } - explicit LocalPathName(const eckit::PathName& path) : - LocalPathName(path.path(), false, true) {} + explicit LocalPathName(const PathName& path); LocalPathName(const LocalPathName& p) : path_(p.path_) {}