Răsfoiți Sursa

Implemented file_createFolder.

David Piuva 3 ani în urmă
părinte
comite
bdef27363e
2 a modificat fișierele cu 22 adăugiri și 3 ștergeri
  1. 15 0
      Source/DFPSR/api/fileAPI.cpp
  2. 7 3
      Source/DFPSR/api/fileAPI.h

+ 15 - 0
Source/DFPSR/api/fileAPI.cpp

@@ -608,4 +608,19 @@ void file_getPathEntries(const ReadableString& path, std::function<void(Readable
 	}
 }
 
+bool file_createFolder(const ReadableString &path) {
+	bool result = false;
+	String optimizedPath = file_optimizePath(path, LOCAL_PATH_SYNTAX);
+	Buffer buffer;
+	const NativeChar *nativePath = toNativeString(optimizedPath, buffer);
+	#ifdef USE_MICROSOFT_WINDOWS
+		// Create folder with permissions inherited.
+		result = (CreateDirectoryW(nativePath, nullptr) != 0);
+	#else
+		// Create folder with default permissions. Read, write and search for owner and group. Read and search for others.
+		result = (mkdir(nativePath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0);
+	#endif
+	return result;
+}
+
 }

+ 7 - 3
Source/DFPSR/api/fileAPI.h

@@ -24,9 +24,6 @@
 /*
 TODO:
 * Test that overwriting a large file with a smaller file does not leave anything from the overwritten file on any system.
-* bool file_createFolder(const ReadableString& path);
-	WINBASEAPI WINBOOL WINAPI CreateDirectoryW (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
-	mkdir on Posix
 * bool file_remove(const ReadableString& path);
 	WINBASEAPI WINBOOL WINAPI DeleteFileW (LPCWSTR lpFileName);
 */
@@ -239,6 +236,13 @@ namespace dsr {
 	// Post-condition: Returns true iff the folder could be found.
 	bool file_getFolderContent(const ReadableString& folderPath, std::function<void(const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType)> action);
 
+	// Path-syntax: According to the local computer.
+	// Access permissions: Default settings according to the local operating system, either inherited from the parent folder or no specific restrictions.
+	// Pre-condition: The parent of path must already exist, because only one folder is created.
+	// Side-effects: Creates a folder at path.
+	// Post-condition: Returns true iff the operation was successful.
+	bool file_createFolder(const ReadableString &path);
+
 	// A theoretical version of file_getParentFolder for evaluation on a theoretical system without actually calling file_getCurrentPath or running on the given system.
 	// Path-syntax: Depends on pathSyntax argument.
 	// Post-condition: Returns the absolute parent to the given path, or U"?" if trying to leave the root or use a tilde home alias.