From e3b9e5a3d14b000788f7015de711921503bf6705 Mon Sep 17 00:00:00 2001 From: TryExceptElse Date: Thu, 25 Nov 2021 21:58:11 -0800 Subject: [PATCH] Handle ENOTDIR errno as indicating a path does not exist. Previously, Path::exists() would produce an exception when a parent of the checked path existed, but was not a directory. For example, if the user called `Path("foo/baz.txt").exists()` when "foo" was a file. This change makes Pathie act more similarly to path libraries such as Python's pathlib, which returns false given the same inputs. --- src/path.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/path.cpp b/src/path.cpp index 56b6401..eb1220e 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -1478,7 +1478,7 @@ bool Path::exists() const if (access(nstr.c_str(), F_OK) == -1) { int errsav = errno; - if (errsav == ENOENT) { + if (errsav == ENOENT || errsav == ENOTDIR) { return false; } else { @@ -1491,7 +1491,7 @@ bool Path::exists() const std::wstring utf16 = utf8_to_utf16(m_path); if (_waccess(utf16.c_str(), F_OK) == -1) { int errsav = errno; - if (errsav == ENOENT) { + if (errsav == ENOENT || errsav == ENOTDIR) { return false; } else {