diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-13 10:30:18 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-13 10:30:18 +0100 |
commit | e9d53ebec7a17b11761b5fee1c2183cff3110dd5 (patch) | |
tree | 9628a4caf18f812cee0a71ed849b546f3275e95d | |
parent | 3c395e56140c991ea776fedde0eaba230060c767 (diff) | |
download | sciteco-e9d53ebec7a17b11761b5fee1c2183cff3110dd5.tar.gz |
try to canonicalize paths to non-existent files
allows you to edit non-existing files with a predefined name. it is completely canonicalized when it is saved
-rw-r--r-- | qbuffers.cpp | 31 | ||||
-rw-r--r-- | qbuffers.h | 3 |
2 files changed, 25 insertions, 9 deletions
diff --git a/qbuffers.cpp b/qbuffers.cpp index d0f11cf..e72c730 100644 --- a/qbuffers.cpp +++ b/qbuffers.cpp @@ -264,10 +264,16 @@ Ring::save(const gchar *filename) buffer, size, NULL)) return false; - if (filename) { - undo.push_str(current->filename); - current->set_filename(filename); - } + /* + * FIXME: necessary also if the filename was not specified but the file + * is (was) new, in order to canonicalize the filename. + * May be circumvented by cananonicalizing without requiring the file + * name to exist (like readlink -f) + */ + //if (filename) { + undo.push_str(current->filename); + current->set_filename(filename ? : current->filename); + //} return true; } @@ -301,6 +307,7 @@ Ring::~Ring() gchar * get_absolute_path(const gchar *path) { + /* FIXME: see Unix implementation */ return path ? g_file_read_link(path, NULL) : NULL; } @@ -309,16 +316,24 @@ get_absolute_path(const gchar *path) gchar * get_absolute_path(const gchar *path) { + gchar buf[PATH_MAX]; gchar *resolved; if (!path) return NULL; - resolved = (gchar *)g_malloc(PATH_MAX); - if (!realpath(path, resolved)) { - g_free(resolved); - 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, NULL); + g_free(cwd); + } + } else { + resolved = g_strdup(buf); } + return resolved; } @@ -177,8 +177,9 @@ public: inline void set_filename(const gchar *filename) { + gchar *resolved = get_absolute_path(filename); g_free(Buffer::filename); - Buffer::filename = get_absolute_path(filename); + Buffer::filename = resolved; } inline void |