fx.io: update all path parameters to be fx_values
This commit is contained in:
+25
-20
@@ -1,3 +1,5 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "misc.h"
|
||||
#include "posix.h"
|
||||
|
||||
@@ -84,13 +86,13 @@ static fx_result file_open_shadow(
|
||||
= fx_path_create_from_cstr(fx_string_get_cstr(filename));
|
||||
fx_string_unref(filename);
|
||||
|
||||
const fx_path *parts[] = {
|
||||
dir,
|
||||
shadow_filename,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(dir),
|
||||
&FX_VALUE_OBJECT(shadow_filename),
|
||||
};
|
||||
|
||||
fx_path *shadow_filepath
|
||||
= fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
= fx_path_join_array(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path_unref(dir);
|
||||
fx_path_unref(shadow_filename);
|
||||
|
||||
@@ -101,7 +103,7 @@ static fx_result file_open_shadow(
|
||||
fx_file *shadow_file;
|
||||
fx_result status = fx_file_open(
|
||||
FX_DIRECTORY_ROOT,
|
||||
shadow_filepath,
|
||||
FX_VALUE_OBJECT(shadow_filepath),
|
||||
mode,
|
||||
&shadow_file);
|
||||
fx_path_unref(shadow_filepath);
|
||||
@@ -227,12 +229,14 @@ static enum fx_status file_swap_shadow(
|
||||
z__fx_io_generate_tmp_filename(tmp_name, sizeof tmp_name);
|
||||
fx_path *tmp_name_p = fx_path_create_from_cstr(tmp_name);
|
||||
|
||||
const fx_path *parts[] = {
|
||||
dir_path,
|
||||
tmp_name_p,
|
||||
const fx_value *parts[] = {
|
||||
&FX_VALUE_OBJECT(dir_path),
|
||||
&FX_VALUE_OBJECT(tmp_name_p),
|
||||
};
|
||||
|
||||
tmp_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
tmp_path = fx_path_join_array(
|
||||
parts,
|
||||
sizeof parts / sizeof parts[0]);
|
||||
|
||||
fx_path_unref(tmp_name_p);
|
||||
|
||||
@@ -248,11 +252,15 @@ static enum fx_status file_swap_shadow(
|
||||
|
||||
int err;
|
||||
|
||||
err = rename(fx_path_get_cstr(main_file->path), fx_path_get_cstr(tmp_path));
|
||||
err = rename(
|
||||
fx_path_get_cstr(main_file->path),
|
||||
fx_path_get_cstr(tmp_path));
|
||||
err = rename(
|
||||
fx_path_get_cstr(shadow_file->path),
|
||||
fx_path_get_cstr(main_file->path));
|
||||
err = rename(fx_path_get_cstr(tmp_path), fx_path_get_cstr(shadow_file->path));
|
||||
err = rename(
|
||||
fx_path_get_cstr(tmp_path),
|
||||
fx_path_get_cstr(shadow_file->path));
|
||||
|
||||
fx_path_unref(tmp_path);
|
||||
|
||||
@@ -406,11 +414,10 @@ static enum fx_status stream_tell(const fx_stream *stream, size_t *pos)
|
||||
|
||||
fx_result fx_file_open(
|
||||
fx_directory *root,
|
||||
const fx_path *path,
|
||||
fx_value path,
|
||||
enum fx_file_mode mode,
|
||||
fx_file **out)
|
||||
{
|
||||
const fx_path *file_path = path;
|
||||
unsigned int flags = fx_mode_to_unix_mode(mode);
|
||||
|
||||
if (flags == (unsigned int)-1) {
|
||||
@@ -422,16 +429,14 @@ fx_result fx_file_open(
|
||||
if (root) {
|
||||
root_path = fx_directory_get_path(root);
|
||||
} else {
|
||||
root_path = fx_path_create_cwd();
|
||||
root_path = fx_path_get_system(FX_PATH_CWD);
|
||||
free_root_path = true;
|
||||
}
|
||||
|
||||
const fx_path *parts[] = {
|
||||
root_path,
|
||||
file_path,
|
||||
};
|
||||
const fx_value *parts[] = {};
|
||||
|
||||
fx_path *abs_path = fx_path_join(parts, sizeof parts / sizeof parts[0]);
|
||||
fx_path *abs_path
|
||||
= fx_path_join_list(2, &FX_VALUE_OBJECT(root_path), &path);
|
||||
|
||||
if (free_root_path) {
|
||||
fx_path_unref((fx_path *)root_path);
|
||||
@@ -492,7 +497,7 @@ fx_result fx_file_open_temp(enum fx_file_mode mode, fx_file **out)
|
||||
|
||||
fx_result status = fx_file_open(
|
||||
FX_DIRECTORY_ROOT,
|
||||
rpath,
|
||||
FX_VALUE_OBJECT(rpath),
|
||||
mode | FX_FILE_CREATE_ONLY,
|
||||
out);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user