libobs/util: Use os_safe_replace in safe file writes

This commit is contained in:
jp9000
2017-05-04 18:23:23 -07:00
parent 651d80c0df
commit 6d3777129d
2 changed files with 4 additions and 15 deletions

View File

@@ -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);

View File

@@ -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);