aboutsummaryrefslogtreecommitdiff
path: root/source/Host/common/FileSpec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/common/FileSpec.cpp')
-rw-r--r--source/Host/common/FileSpec.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/source/Host/common/FileSpec.cpp b/source/Host/common/FileSpec.cpp
index ceb094b9ede7..8885a791d88c 100644
--- a/source/Host/common/FileSpec.cpp
+++ b/source/Host/common/FileSpec.cpp
@@ -107,7 +107,7 @@ FileSpec::ResolveUsername (llvm::SmallVectorImpl<char> &path)
return;
llvm::StringRef path_str(path.data(), path.size());
- size_t slash_pos = path_str.find_first_of("/", 1);
+ size_t slash_pos = path_str.find('/', 1);
if (slash_pos == 1 || path.size() == 1)
{
// A path of ~/ resolves to the current user's home dir
@@ -789,6 +789,28 @@ FileSpec::GetFileType () const
return eFileTypeInvalid;
}
+bool
+FileSpec::IsSymbolicLink () const
+{
+ char resolved_path[PATH_MAX];
+ if (!GetPath (resolved_path, sizeof (resolved_path)))
+ return false;
+
+#ifdef _WIN32
+ auto attrs = ::GetFileAttributes (resolved_path);
+ if (attrs == INVALID_FILE_ATTRIBUTES)
+ return false;
+
+ return (attrs & FILE_ATTRIBUTE_REPARSE_POINT);
+#else
+ struct stat file_stats;
+ if (::lstat (resolved_path, &file_stats) != 0)
+ return false;
+
+ return (file_stats.st_mode & S_IFMT) == S_IFLNK;
+#endif
+}
+
uint32_t
FileSpec::GetPermissions () const
{
@@ -1409,7 +1431,7 @@ FileSpec::AppendPathComponent(const char *new_path)
return;
}
StreamString stream;
- if (m_filename.IsEmpty())
+ if (m_filename.IsEmpty() || (m_filename.GetLength() == 1 && m_filename.GetCString()[0] == '.'))
stream.Printf("%s/%s", m_directory.GetCString(), new_path);
else if (m_directory.IsEmpty())
stream.Printf("%s/%s", m_filename.GetCString(), new_path);