diff options
author | B. Stack <bgstack15@gmail.com> | 2021-12-06 07:57:52 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2021-12-06 07:57:52 -0500 |
commit | 226ac347c51e21440d1740d85b5e9912d1ce08e5 (patch) | |
tree | 2999df8f80b28d0f7f60a84b7f75d613e280bba1 /zen/file_access.cpp | |
parent | Merge branch 'b11.14' into 'master' (diff) | |
download | FreeFileSync-226ac347c51e21440d1740d85b5e9912d1ce08e5.tar.gz FreeFileSync-226ac347c51e21440d1740d85b5e9912d1ce08e5.tar.bz2 FreeFileSync-226ac347c51e21440d1740d85b5e9912d1ce08e5.zip |
add upstream 11.15
Diffstat (limited to 'zen/file_access.cpp')
-rw-r--r-- | zen/file_access.cpp | 65 |
1 files changed, 1 insertions, 64 deletions
diff --git a/zen/file_access.cpp b/zen/file_access.cpp index db4f2505..6940b22f 100644 --- a/zen/file_access.cpp +++ b/zen/file_access.cpp @@ -29,71 +29,8 @@ using namespace zen; -std::optional<PathComponents> zen::parsePathComponents(const Zstring& itemPath) -{ - auto doParse = [&](int sepCountVolumeRoot, bool rootWithSep) -> std::optional<PathComponents> - { - const Zstring itemPathFmt = appendSeparator(itemPath); //simplify analysis of root without separator, e.g. \\server-name\share - int sepCount = 0; - for (auto it = itemPathFmt.begin(); it != itemPathFmt.end(); ++it) - if (*it == FILE_NAME_SEPARATOR) - if (++sepCount == sepCountVolumeRoot) - { - Zstring rootPath(itemPathFmt.begin(), rootWithSep ? it + 1 : it); - - Zstring relPath(it + 1, itemPathFmt.end()); - trim(relPath, true, true, [](Zchar c) { return c == FILE_NAME_SEPARATOR; }); - - return PathComponents({rootPath, relPath}); - } - return {}; - }; - - std::optional<PathComponents> pc; //"/media/zenju/" and "/Volumes/" should not fail to parse - - if (!pc && startsWith(itemPath, "/mnt/")) //e.g. /mnt/DEVICE_NAME - pc = doParse(3 /*sepCountVolumeRoot*/, false /*rootWithSep*/); - - if (!pc && startsWith(itemPath, "/media/")) //Ubuntu: e.g. /media/zenju/DEVICE_NAME - if (const char* username = ::getenv("USER")) - if (startsWith(itemPath, std::string("/media/") + username + "/")) - pc = doParse(4 /*sepCountVolumeRoot*/, false /*rootWithSep*/); - - if (!pc && startsWith(itemPath, "/run/media/")) //CentOS, Suse: e.g. /run/media/zenju/DEVICE_NAME - if (const char* username = ::getenv("USER")) - if (startsWith(itemPath, std::string("/run/media/") + username + "/")) - pc = doParse(5 /*sepCountVolumeRoot*/, false /*rootWithSep*/); - - if (!pc && startsWith(itemPath, "/run/user/")) //Ubuntu, e.g.: /run/user/1000/gvfs/smb-share:server=192.168.62.145,share=folder - { - Zstring tmp(itemPath.begin() + strLength("/run/user/"), itemPath.end()); - tmp = beforeFirst(tmp, "/gvfs/", IfNotFoundReturn::none); - if (!tmp.empty() && std::all_of(tmp.begin(), tmp.end(), [](char c) { return isDigit(c); })) - /**/pc = doParse(6 /*sepCountVolumeRoot*/, false /*rootWithSep*/); - } - - - if (!pc && startsWith(itemPath, "/")) - pc = doParse(1 /*sepCountVolumeRoot*/, true /*rootWithSep*/); - - return pc; -} - - -std::optional<Zstring> zen::getParentFolderPath(const Zstring& itemPath) +namespace { - if (const std::optional<PathComponents> comp = parsePathComponents(itemPath)) - { - if (comp->relPath.empty()) - return std::nullopt; - - const Zstring parentRelPath = beforeLast(comp->relPath, FILE_NAME_SEPARATOR, IfNotFoundReturn::none); - if (parentRelPath.empty()) - return comp->rootPath; - return appendSeparator(comp->rootPath) + parentRelPath; - } - assert(false); - return std::nullopt; } |