summaryrefslogtreecommitdiff
path: root/zen/resolve_path.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
committerB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
commit2a026bc7d76875b88700bebc7c5a801fef881bfd (patch)
treef820b53379f3d14e103e2663e8b0ecd38d1b2105 /zen/resolve_path.cpp
parentMerge branch 'b11.21' into 'master' (diff)
parentadd upstream 11.22 (diff)
downloadFreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.tar.gz
FreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.tar.bz2
FreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.zip
Merge branch '11.22' into 'master'11.22
add upstream 11.22 See merge request opensource-tracking/FreeFileSync!45
Diffstat (limited to 'zen/resolve_path.cpp')
-rw-r--r--zen/resolve_path.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/zen/resolve_path.cpp b/zen/resolve_path.cpp
index 2b1a82d3..357dab6a 100644
--- a/zen/resolve_path.cpp
+++ b/zen/resolve_path.cpp
@@ -9,8 +9,10 @@
#include "thread.h"
#include "file_access.h"
- #include <stdlib.h> //getenv()
- #include <unistd.h> //getcwd()
+#include <zen/sys_info.h>
+ // #include <stdlib.h> //getenv()
+ #include <unistd.h> //getuid()
+ #include <pwd.h> //getpwuid_r()
using namespace zen;
@@ -21,7 +23,7 @@ std::optional<Zstring> getEnvironmentVar(const Zchar* name)
{
assert(runningOnMainThread()); //getenv() is not thread-safe!
- const char* buffer = ::getenv(name); //no extended error reporting
+ const char* buffer = ::getenv(name); //no ownership transfer + no extended error reporting
if (!buffer)
return {};
Zstring value(buffer);
@@ -58,20 +60,19 @@ Zstring resolveRelativePath(const Zstring& relativePath)
if (!startsWith(pathTmp, FILE_NAME_SEPARATOR)) //absolute names are exactly those starting with a '/'
{
/* basic support for '~': strictly speaking this is a shell-layer feature, so "realpath()" won't handle it
- https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html
-
- https://linux.die.net/man/3/getpwuid: An application that wants to determine its user's home directory
- should inspect the value of HOME (rather than the value getpwuid(getuid())->pw_dir) since this allows
- the user to modify their notion of "the home directory" during a login session. */
+ https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html */
if (startsWith(pathTmp, "~/") || pathTmp == "~")
{
- if (const std::optional<Zstring> homeDir = getEnvironmentVar("HOME"))
- {
+ try
+ {
+ const Zstring& homePath = getUserHome(); //throw FileError
+
if (startsWith(pathTmp, "~/"))
- pathTmp = appendPath(*homeDir, pathTmp.c_str() + 2);
+ pathTmp = appendPath(homePath, pathTmp.c_str() + 2);
else //pathTmp == "~"
- pathTmp = *homeDir;
- }
+ pathTmp = homePath;
+ }
+ catch (FileError&) {}
//else: error! no further processing!
}
else
@@ -238,8 +239,7 @@ Zstring zen::getResolvedFilePath(const Zstring& pathPhrase) //noexcept
path = expandMacros(path); //expand before trimming!
- //remove leading/trailing whitespace before allowing misinterpretation in applyLongPathPrefix()
- trim(path); //attention: don't remove all whitespace from right, e.g. 0xa0 may be used as part of a folder name
+ trim(path); //remove leading/trailing whitespace before allowing misinterpretation in applyLongPathPrefix()
{
path = expandVolumeName(path); //may block for slow USB sticks and idle HDDs!
bgstack15