浏览代码

Optionally treating home alias as a root, because it contains a root before the arbitrary user account.

David Piuva 3 年之前
父节点
当前提交
9293b2eba6
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 4 2
      Source/DFPSR/api/fileAPI.cpp
  2. 2 1
      Source/DFPSR/api/fileAPI.h

+ 4 - 2
Source/DFPSR/api/fileAPI.cpp

@@ -169,13 +169,15 @@ ReadableString file_getParentFolder(const ReadableString &path) {
 	return string_before(path, getLastSeparator(path, 0));
 }
 
-bool file_hasRoot(const ReadableString &path) {
+bool file_hasRoot(const ReadableString &path, bool treatHomeFolderAsRoot) {
 	#ifdef USE_MICROSOFT_WINDOWS
 		// If a colon is found, it is a root path.
 		return string_findFirst(path, U':') > -1;
 	#else
 		// If the path begins with a separator, it is the root folder in Posix systems.
-		return path[0] == U'/';
+		// If the path begins with a tilde (~), it is a home folder.
+		DsrChar firstC = path[0];
+		return firstC == U'/' || (treatHomeFolderAsRoot && firstC == U'~');
 	#endif
 }
 

+ 2 - 1
Source/DFPSR/api/fileAPI.h

@@ -96,7 +96,8 @@ namespace dsr {
 	String file_combinePaths(const ReadableString &a, const ReadableString &b);
 
 	// Returns true iff path contains a root, according to the local path syntax.
-	bool file_hasRoot(const ReadableString &path);
+	// If treatHomeFolderAsRoot is true, starting from the home folder using the Posix ~ alias will be allowed.
+	bool file_hasRoot(const ReadableString &path, bool treatHomeFolderAsRoot = true);
 
 	// DSR_MAIN_CALLER is a convenient wrapper for getting input arguments as a list of portable Unicode strings.
 	//   The actual main function gets placed in DSR_MAIN_CALLER, which calls the given function.