From 52572d5b80798db40ecc252a408248591b9534c6 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 2 Apr 2023 15:46:26 +0300 Subject: [PATCH] (vfs_path_new): add argument to create relative path object. Signed-off-by: Andrew Borodin --- lib/vfs/path.c | 15 +++++++-------- lib/vfs/path.h | 2 +- src/filemanager/panel.c | 7 ++----- tests/lib/vfs/relative_cd.c | 3 +-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/vfs/path.c b/lib/vfs/path.c index eda7690c8..da552a45c 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -380,7 +380,7 @@ vfs_path_from_str_deprecated_parser (char *path) struct vfs_class *class; const char *local, *op; - vpath = vfs_path_new (); + vpath = vfs_path_new (FALSE); while ((class = _vfs_split_with_semi_skip_count (path, &local, &op, 0)) != NULL) { @@ -443,8 +443,7 @@ vfs_path_from_str_uri_parser (char *path) vfs_path_element_t *element; char *url_delimiter; - vpath = vfs_path_new (); - vpath->relative = path != NULL && !IS_PATH_SEP (*path); + vpath = vfs_path_new (path != NULL && !IS_PATH_SEP (*path)); while ((url_delimiter = g_strrstr (path, VFS_PATH_URL_DELIMITER)) != NULL) { @@ -776,12 +775,13 @@ vfs_path_from_str (const char *path_str) */ vfs_path_t * -vfs_path_new (void) +vfs_path_new (gboolean relative) { vfs_path_t *vpath; vpath = g_new0 (vfs_path_t, 1); vpath->path = g_array_new (FALSE, TRUE, sizeof (vfs_path_element_t *)); + vpath->relative = relative; return vpath; } @@ -936,8 +936,7 @@ vfs_path_clone (const vfs_path_t * vpath) if (vpath == NULL) return NULL; - new_vpath = vfs_path_new (); - new_vpath->relative = vpath->relative; + new_vpath = vfs_path_new (vpath->relative); for (vpath_element_index = 0; vpath_element_index < vfs_path_elements_count (vpath); vpath_element_index++) @@ -1181,7 +1180,7 @@ vfs_path_deserialize (const char *data, GError ** mcerror) if (cpath == NULL) return NULL; - vpath = vfs_path_new (); + vpath = vfs_path_new (FALSE); for (element_index = 0;; element_index++) { @@ -1321,7 +1320,7 @@ vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...) if (first_vpath == NULL) return NULL; - ret_vpath = vfs_path_new (); + ret_vpath = vfs_path_new (FALSE); va_start (args, first_vpath); do diff --git a/lib/vfs/path.h b/lib/vfs/path.h index 087058ff0..088711165 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -57,7 +57,7 @@ typedef struct /*** declarations of public functions ************************************************************/ -vfs_path_t *vfs_path_new (void); +vfs_path_t *vfs_path_new (gboolean relative); vfs_path_t *vfs_path_clone (const vfs_path_t * vpath); void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index); char *vfs_path_free (vfs_path_t * path, gboolean free_str); diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index ae9523790..e0ef9a2c3 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -1247,10 +1247,7 @@ panel_correct_path_to_show (const WPanel * panel) } } else - { - last_vpath = vfs_path_new (); - last_vpath->relative = TRUE; - } + last_vpath = vfs_path_new (TRUE); vfs_path_add_element (last_vpath, path_element); return_path = @@ -4947,7 +4944,7 @@ remove_encoding_from_path (const vfs_path_t * vpath) GString *tmp_conv; int indx; - ret_vpath = vfs_path_new (); + ret_vpath = vfs_path_new (FALSE); tmp_conv = g_string_new (""); diff --git a/tests/lib/vfs/relative_cd.c b/tests/lib/vfs/relative_cd.c index 61c50f33e..124775223 100644 --- a/tests/lib/vfs/relative_cd.c +++ b/tests/lib/vfs/relative_cd.c @@ -175,8 +175,7 @@ START_TEST (test_vpath_to_str_filter) path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1)); vfs_path_free (vpath, TRUE); - last_vpath = vfs_path_new (); - last_vpath->relative = TRUE; + last_vpath = vfs_path_new (TRUE); vfs_path_add_element (last_vpath, path_element); -- 2.11.4.GIT