From 018904f0ec59244645187b72f01bedcf716ab40c Mon Sep 17 00:00:00 2001 From: Mark Naughton Date: Fri, 19 May 2023 18:37:55 +0100 Subject: Add write permissions check on output folder --- src/path.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/path.cpp') 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 *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 -- cgit v1.2.3