[gnome-disk-utility] utils: make unfuse_path() replace $HOME with ~
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] utils: make unfuse_path() replace $HOME with ~
- Date: Wed, 22 May 2013 02:24:47 +0000 (UTC)
commit 99a3c8ea7c48459ae996d2187e1c79e3cb95d26d
Author: David Zeuthen <zeuthen gmail com>
Date: Tue May 21 18:31:05 2013 -0700
utils: make unfuse_path() replace $HOME with ~
Because it's more natural to convey
~/Downloads/foo.iso
than
/home/davidz/Downloads/foo.iso
Signed-off-by: David Zeuthen <zeuthen gmail com>
src/libgdu/gduutils.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c
index 8da612d..ca8e097 100644
--- a/src/libgdu/gduutils.c
+++ b/src/libgdu/gduutils.c
@@ -194,7 +194,9 @@ gdu_utils_unfuse_path (const gchar *path)
gchar *ret;
GFile *file;
gchar *uri;
+ const gchar *home;
+ /* Map GVfs FUSE paths to GVfs URIs */
file = g_file_new_for_path (path);
uri = g_file_get_uri (file);
if (g_str_has_prefix (uri, "file:"))
@@ -208,6 +210,24 @@ gdu_utils_unfuse_path (const gchar *path)
g_object_unref (file);
g_free (uri);
+ /* Replace $HOME with ~ */
+ home = g_get_home_dir ();
+ if (g_str_has_prefix (ret, home))
+ {
+ size_t home_len = strlen (home);
+ if (home_len > 2)
+ {
+ if (home[home_len - 1] == '/')
+ home_len--;
+ if (ret[home_len] == '/')
+ {
+ gchar *tmp = ret;
+ ret = g_strdup_printf ("~/%s", ret + home_len + 1);
+ g_free (tmp);
+ }
+ }
+ }
+
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]