mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Add write permissions check on output folder
This commit is contained in:
+18
-1
@@ -1504,7 +1504,8 @@ gb_internal bool init_build_paths(String init_filename) {
|
|||||||
if (build_context.metrics.os == TargetOs_windows) {
|
if (build_context.metrics.os == TargetOs_windows) {
|
||||||
output_extension = STR_LIT("exe");
|
output_extension = STR_LIT("exe");
|
||||||
} else if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
} else if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
||||||
output_extension = make_string(nullptr, 0);
|
// Do nothing: we don't want the .bin extension
|
||||||
|
// when cross compiling
|
||||||
} else if (path_is_directory(last_path_element(bc->build_paths[BuildPath_Main_Package].basename))) {
|
} else if (path_is_directory(last_path_element(bc->build_paths[BuildPath_Main_Package].basename))) {
|
||||||
// Add .bin extension to avoid collision
|
// Add .bin extension to avoid collision
|
||||||
// with package directory name
|
// with package directory name
|
||||||
@@ -1624,6 +1625,22 @@ gb_internal bool init_build_paths(String init_filename) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path_is_directory(bc->build_paths[BuildPath_Output])) {
|
||||||
|
String output_file = path_to_string(ha, bc->build_paths[BuildPath_Output]);
|
||||||
|
defer (gb_free(ha, output_file.text));
|
||||||
|
gb_printf_err("Output path %.*s is a directory.\n", LIT(output_file));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//nocheckin char const *pathname = (char *)bc->build_paths[BuildPath_Output].basename.text;
|
||||||
|
|
||||||
|
if (!write_directory(bc->build_paths[BuildPath_Output].basename)) {
|
||||||
|
String output_file = path_to_string(ha, bc->build_paths[BuildPath_Output]);
|
||||||
|
defer (gb_free(ha, output_file.text));
|
||||||
|
gb_printf_err("No write permissions for output path: %.*s\n", LIT(output_file));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (bc->target_features_string.len != 0) {
|
if (bc->target_features_string.len != 0) {
|
||||||
enable_target_feature({}, bc->target_features_string);
|
enable_target_feature({}, bc->target_features_string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -419,7 +419,43 @@ gb_internal ReadDirectoryError read_directory(String path, Array<FileInfo> *fi)
|
|||||||
|
|
||||||
return ReadDirectory_None;
|
return ReadDirectory_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error Implement read_directory
|
#error Implement read_directory
|
||||||
#endif
|
#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
|
||||||
|
|||||||
Reference in New Issue
Block a user