libobs/util: Use os_safe_replace in safe file writes
This commit is contained in:
@@ -445,14 +445,10 @@ int config_save_safe(config_t *config, const char *temp_ext,
|
||||
if (*backup_ext != '.')
|
||||
dstr_cat(&backup_file, ".");
|
||||
dstr_cat(&backup_file, backup_ext);
|
||||
|
||||
os_unlink(backup_file.array);
|
||||
os_rename(file, backup_file.array);
|
||||
} else {
|
||||
os_unlink(file);
|
||||
}
|
||||
|
||||
os_rename(temp_file.array, file);
|
||||
if (os_safe_replace(file, temp_file.array, backup_file.array) != 0)
|
||||
ret = CONFIG_ERROR;
|
||||
|
||||
cleanup:
|
||||
pthread_mutex_unlock(&config->mutex);
|
||||
|
@@ -297,17 +297,10 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str,
|
||||
if (*backup_ext != '.')
|
||||
dstr_cat(&backup_path, ".");
|
||||
dstr_cat(&backup_path, backup_ext);
|
||||
|
||||
os_unlink(backup_path.array);
|
||||
os_rename(path, backup_path.array);
|
||||
|
||||
dstr_free(&backup_path);
|
||||
} else {
|
||||
os_unlink(path);
|
||||
}
|
||||
|
||||
os_rename(temp_path.array, path);
|
||||
success = true;
|
||||
if (os_safe_replace(path, temp_path.array, backup_path.array) == 0)
|
||||
success = true;
|
||||
|
||||
cleanup:
|
||||
dstr_free(&backup_path);
|
||||
|
Reference in New Issue
Block a user