diff options
| author | Mark Naughton <mark@marknaughton.com> | 2023-05-19 18:37:55 +0100 |
|---|---|---|
| committer | Mark Naughton <mark@marknaughton.com> | 2023-05-19 18:37:55 +0100 |
| commit | 018904f0ec59244645187b72f01bedcf716ab40c (patch) | |
| tree | f2d3f6c77f41631ea6199b54c3ef67ea38c574aa /src/path.cpp | |
| parent | 413077a5d9ce55850bbb64747e1e7a813e356e5b (diff) | |
Add write permissions check on output folder
Diffstat (limited to 'src/path.cpp')
| -rw-r--r-- | src/path.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/path.cpp b/src/path.cpp index 3054e3b57..c9887e9ca 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -419,7 +419,43 @@ gb_internal ReadDirectoryError read_directory(String path, Array<FileInfo> *fi) return ReadDirectory_None;
}
+
+
#else
#error Implement read_directory
#endif
+#if !defined(GB_SYSTEM_WINDOWS)
+gb_internal bool write_directory(String path) {
+ char const *pathname = (char *) path.text;
+
+ if (access(pathname, W_OK) < 0) {
+ return false;
+ }
+
+ return true;
+}
+#else
+gb_internal bool write_directory(String path) {
+ String16wstr = string_to_string16(heap_allocator(), path);
+ LPCWSTR wdirectory_name = wstr.text;
+
+ HANDLE directory = CreateFileW(wdirectory_name,
+ GENERIC_WRITE,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL);
+
+ if (directory == INVALID_HANDLE_VALUE) {
+ DWORD error_code = GetLastError();
+ if (error_code == ERROR_ACCESS_DENIED) {
+ return false;
+ }
+ }
+
+ CloseHandle(directory);
+ return true;
+}
+#endif
|