diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-07-27 19:54:23 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-07-27 19:54:23 +0200 |
commit | 7b3f7da0ec70e7be0e3db9524d092d9e138ed448 (patch) | |
tree | 7a2f615557d42fabea7b05ed14ff6e2652c9d67a /src | |
parent | 32e03eb30fb548a773ca013f7e0cc548fc7b5b2e (diff) | |
download | sciteco-7b3f7da0ec70e7be0e3db9524d092d9e138ed448.tar.gz |
fixed fallback implementation of get_absolute_path() on misc platforms
* the old implementation was totally broken, which was to be expected
* we can at least provide a version that always returns an absolute
path, even though it does not canonicalizes
* fixes e.g. Haiku builds for the time being.
Haiku however is mostly POSIX compliant and could be handled
like UNIX.
* simplified the UNIX implementation of get_absolute_path()
Diffstat (limited to 'src')
-rw-r--r-- | src/ioview.cpp | 39 | ||||
-rw-r--r-- | src/ioview.h | 7 |
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. |