aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/ioview.cpp39
-rw-r--r--src/ioview.h7
2 files changed, 33 insertions, 13 deletions
diff --git a/src/ioview.cpp b/src/ioview.cpp
index 5f50580..6cab3f9 100644
--- a/src/ioview.cpp
+++ b/src/ioview.cpp
@@ -709,16 +709,14 @@ get_absolute_path(const gchar *path)
if (!path)
return NULL;
- if (!realpath(path, buf)) {
- if (g_path_is_absolute(path)) {
- resolved = g_strdup(path);
- } else {
- gchar *cwd = g_get_current_dir();
- resolved = g_build_filename(cwd, path, NIL);
- g_free(cwd);
- }
- } else {
+ if (realpath(path, buf)) {
resolved = g_strdup(buf);
+ } else if (g_path_is_absolute(path)) {
+ resolved = g_strdup(path);
+ } else {
+ gchar *cwd = g_get_current_dir();
+ resolved = g_build_filename(cwd, path, NIL);
+ g_free(cwd);
}
return resolved;
@@ -754,15 +752,32 @@ file_is_visible(const gchar *path)
return !(get_file_attributes(path) & FILE_ATTRIBUTE_HIDDEN);
}
-#else
+#else /* !G_OS_UNIX && !G_OS_WIN32 */
/*
- * FIXME: I doubt that works on any platform...
+ * This will never canonicalize relative paths.
+ * I.e. the absolute path will often contain
+ * relative components, even if `path` exists.
+ * The only exception would be a simple filename
+ * not containing any "..".
*/
gchar *
get_absolute_path(const gchar *path)
{
- return path ? g_file_read_link(path, NULL) : NULL;
+ gchar *resolved;
+
+ if (!path)
+ return NULL;
+
+ if (g_path_is_absolute(path)) {
+ resolved = g_strdup(path);
+ } else {
+ gchar *cwd = g_get_current_dir();
+ resolved = g_build_filename(cwd, path, NIL);
+ g_free(cwd);
+ }
+
+ return resolved;
}
/*
diff --git a/src/ioview.h b/src/ioview.h
index e0f23f4..dddbb9b 100644
--- a/src/ioview.h
+++ b/src/ioview.h
@@ -38,8 +38,13 @@ gchar *expand_path(const gchar *path);
/**
* Get absolute/full version of a possibly relative path.
+ * The path is tried to be canonicalized so it does
+ * not contain relative components.
* Works with existing and non-existing paths (in the latter case,
- * heuristics may be applied.)
+ * heuristics may be applied).
+ * Depending on platform and existence of the path,
+ * canonicalization might fail, but the path returned is
+ * always absolute.
*
* @param path Possibly relative path name.
* @return Newly-allocated absolute path name.