Fix false positives when detecting unwritable save paths

This commit is contained in:
Lior Halphon 2022-07-25 00:26:42 +03:00
parent bcfe36897c
commit c5362023c8
2 changed files with 22 additions and 2 deletions

View File

@ -1049,6 +1049,16 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency)
return fileName;
}
static bool is_path_writeable(const char *path)
{
if (!access(path, W_OK)) return true;
int fd = creat(path, 0644);
if (fd == -1) return false;
close(fd);
unlink(path);
return true;
}
- (int) loadROM
{
__block int ret = 0;
@ -1078,7 +1088,7 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency)
ret = GB_load_rom(&gb, [fileName UTF8String]);
}
if (GB_save_battery_size(&gb)) {
if (access(self.savPath.UTF8String, W_OK)) {
if (!is_path_writeable(self.savPath.UTF8String)) {
GB_log(&gb, "The save path for this ROM is not writeable, progress will not be saved.\n");
}
}

View File

@ -656,6 +656,16 @@ static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type)
}
}
static bool is_path_writeable(const char *path)
{
if (!access(path, W_OK)) return true;
int fd = creat(path, 0644);
if (fd == -1) return false;
close(fd);
unlink(path);
return true;
}
static void run(void)
{
SDL_ShowCursor(SDL_DISABLE);
@ -744,7 +754,7 @@ restart:
battery_save_path_ptr = battery_save_path;
GB_load_battery(&gb, battery_save_path);
if (GB_save_battery_size(&gb)) {
if (access(battery_save_path, W_OK)) {
if (!is_path_writeable(battery_save_path)) {
GB_log(&gb, "The save path for this ROM is not writeable, progress will not be saved.\n");
}
}