[gthumb] Resolve symlinks in a gfile-ish way
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Resolve symlinks in a gfile-ish way
- Date: Sat, 16 May 2009 20:23:26 -0400 (EDT)
commit cb5f98d1a9b141ae2e46eab120aa726e6eab6c15
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Sat May 16 20:22:51 2009 -0400
Resolve symlinks in a gfile-ish way
---
libgthumb/comments.c | 15 +---
libgthumb/file-utils.c | 199 ++++++++++++---------------------------------
libgthumb/file-utils.h | 3 +-
libgthumb/thumb-cache.c | 15 +---
libgthumb/thumb-loader.c | 9 +--
src/dlg-search.c | 16 ++---
6 files changed, 70 insertions(+), 187 deletions(-)
diff --git a/libgthumb/comments.c b/libgthumb/comments.c
index 3c2e21e..7cf2442 100644
--- a/libgthumb/comments.c
+++ b/libgthumb/comments.c
@@ -33,7 +33,6 @@
#include <time.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-result.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
@@ -190,17 +189,9 @@ comments_get_comment_filename (const char *uri,
source_real = g_strdup (uri);
if (resolve_symlinks) {
- char *resolved = NULL;
- GnomeVFSResult result;
-
- result = resolve_all_symlinks (source_real, &resolved);
-
- if (result == GNOME_VFS_OK) {
- g_free (source_real);
- source_real = resolved;
- }
- else
- g_free (resolved);
+ char *resolved = resolve_all_symlinks (source_real);
+ g_free (source_real);
+ source_real = resolved;
}
directory = remove_level_from_path (source_real);
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 8097ee9..39e4a41 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -1527,164 +1527,77 @@ build_uri (const char *s1,
}
-static GnomeVFSResult
-resolve_symlinks (const char *text_uri,
- const char *relative_link,
- char **resolved_text_uri,
- int n_followed_symlinks)
+char *resolve_all_symlinks (const char *uri)
{
- GnomeVFSResult result = GNOME_VFS_OK;
- char *resolved_uri;
- char *uri;
- char *tmp;
- GnomeVFSFileInfo *info;
- const char *path;
- char **names;
- int i;
+ GFile *gfile_full;
+ GFile *gfile_curr;
+ GFile *parent;
+ char *child = NULL;
+ int i=0;
+ char *result;
- *resolved_text_uri = NULL;
-
- if (text_uri == NULL)
- return GNOME_VFS_OK;
- if (*text_uri == '\0')
- return GNOME_VFS_ERROR_INVALID_URI;
-
- info = gnome_vfs_file_info_new ();
-
- if (info == NULL)
- return GNOME_VFS_ERROR_INVALID_URI;
-
- resolved_uri = get_uri_host (text_uri);
-
- tmp = build_uri (text_uri, relative_link, NULL);
- uri = remove_special_dirs_from_path (tmp);
- g_free (tmp);
-
- /* split the uri and resolve one name at a time. */
-
- path = remove_host_from_uri (uri);
- if (path == NULL) {
- *resolved_text_uri = resolved_uri;
- return GNOME_VFS_OK;
- }
-
- names = g_strsplit (path, GNOME_VFS_URI_PATH_STR, -1);
- g_free (uri);
-
- for (i = 0; (result == GNOME_VFS_OK) && (names[i] != NULL); i++) {
- char *try_uri;
- char *symlink;
- char **symlink_names;
- int j;
- char *base_uri;
-
- if (strcmp (names[i], "") == 0)
- continue;
-
- gnome_vfs_file_info_clear (info);
+ if ((uri == NULL) || (*uri == '\0'))
+ return NULL;
- try_uri = g_strconcat (resolved_uri, GNOME_VFS_URI_PATH_STR, names[i], NULL);
+ if (!is_local_file (uri))
+ return g_strdup (uri);
- result = gnome_vfs_get_file_info (try_uri, info, GNOME_VFS_FILE_INFO_DEFAULT);
- if (result != GNOME_VFS_OK) {
- g_free (try_uri);
- break;
+ gfile_full = gfile_new (uri);
+ gfile_curr = gfile_new (uri);
+
+ while ((parent = g_file_get_parent (gfile_curr)) != NULL) {
+ GFileInfo *info;
+ GError *error = NULL;
+ const char *symlink;
+
+ info = g_file_query_info (gfile_curr,
+ G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+ if (error != NULL) {
+ g_warning ("Couldn't obtain symlink info: %s",error->message);
+ g_object_unref (parent);
+ g_object_unref (gfile_curr);
+ g_object_unref (gfile_full);
+ g_free (child);
+ g_error_free (error);
+ return g_strdup (uri);
}
- /* if names[i] isn't a symbolic link add it to the resolved uri and continue */
-
- if (!((info->type == GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) &&
- (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME))) {
+ if (((symlink = g_file_info_get_symlink_target (info)) != NULL) && (i<MAX_SYMLINKS_FOLLOWED)) {
+ i++;
- g_free (resolved_uri);
- resolved_uri = try_uri;
+ g_object_unref (gfile_curr);
+ gfile_curr = g_file_resolve_relative_path (parent, symlink);
- continue;
- }
-
- g_free (try_uri);
+ g_object_unref (gfile_full);
+ if (child != NULL)
+ gfile_full = g_file_resolve_relative_path (gfile_curr, child);
+ else
+ gfile_full = g_file_dup (gfile_curr);
- /* names[i] is a symbolic link */
+ } else {
+ g_object_unref (gfile_curr);
+ gfile_curr = g_file_dup (parent);
- n_followed_symlinks++;
- if (n_followed_symlinks > MAX_SYMLINKS_FOLLOWED) {
- result = GNOME_VFS_ERROR_TOO_MANY_LINKS;
- break;
+ g_free (child);
+ child = g_file_get_relative_path (parent, gfile_full);
}
- /* get the symlink escaping the value info->symlink_name */
-
- symlink = g_strdup ("");
- symlink_names = g_strsplit (info->symlink_name, GNOME_VFS_URI_PATH_STR, -1);
- for (j = 0; symlink_names[j] != NULL; j++) {
- char *symlink_name = symlink_names[j];
- char *e_symlink_name;
-
- if ((strcmp (symlink_name, "..") == 0) || (strcmp (symlink_name, ".") == 0))
- e_symlink_name = g_strdup (symlink_name);
- if (strcmp (symlink_name, "") == 0)
- e_symlink_name = g_strdup (GNOME_VFS_URI_PATH_STR);
- else
- e_symlink_name = gnome_vfs_escape_string (symlink_name);
-
- if (strcmp (symlink, "") == 0) {
- g_free (symlink);
- symlink = e_symlink_name;
- }
- else {
- char *tmp;
-
- tmp = build_uri (symlink, e_symlink_name, NULL);
-
- g_free (symlink);
- g_free (e_symlink_name);
-
- symlink = tmp;
- }
- }
- g_strfreev (symlink_names);
-
- /* if the symlink is absolute reset the base uri, else use
- * the currently resolved uri as base. */
-
- if (symlink[0] == GNOME_VFS_URI_PATH_CHR) {
- g_free (resolved_uri);
- base_uri = get_uri_host (text_uri);
- }
- else
- base_uri = resolved_uri;
-
- /* resolve the new uri recursively */
-
- result = resolve_symlinks (base_uri, symlink, &resolved_uri, n_followed_symlinks);
-
- g_free (base_uri);
- g_free (symlink);
+ g_object_unref (info);
+ g_object_unref (parent);
}
- g_strfreev (names);
- gnome_vfs_file_info_unref (info);
-
- if (result == GNOME_VFS_OK)
- *resolved_text_uri = resolved_uri;
+ result = g_file_get_uri (gfile_full);
+ g_object_unref (gfile_curr);
+ g_object_unref (gfile_full);
+ g_free (child);
return result;
}
-GnomeVFSResult
-resolve_all_symlinks (const char *text_uri,
- char **resolved_text_uri)
-{
- if (! is_local_file (text_uri)) {
- *resolved_text_uri = g_strdup (text_uri);
- return GNOME_VFS_OK;
- }
- else
- return resolve_symlinks (text_uri, "", resolved_text_uri, 0);
-}
-
-
gboolean
uri_is_root (const char *uri)
{
@@ -2416,13 +2329,7 @@ gth_pixbuf_new_from_video (FileData *file,
char *file_uri = NULL;
char *thumbnail_uri;
- if (! (resolve_symlinks
- && is_local_file (file->path)
- && (resolve_all_symlinks (file->path, &file_uri) == GNOME_VFS_OK)))
- {
- file_uri = g_strdup (file->path);
- }
-
+ file_uri = resolve_all_symlinks (file->path);
thumbnail_uri = gnome_thumbnail_factory_lookup (factory,
file_uri,
file->mtime);
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index 5bf31c4..7a395d6 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -174,8 +174,7 @@ GnomeVFSURI * new_uri_from_path (const char *path);
char * build_uri (const char *s1,
const char *s2,
...);
-GnomeVFSResult resolve_all_symlinks (const char *text_uri,
- char **resolved_text_uri);
+char * resolve_all_symlinks (const char *uri);
gboolean uri_is_root (const char *uri);
/* Catalogs */
diff --git a/libgthumb/thumb-cache.c b/libgthumb/thumb-cache.c
index a35e012..e06b568 100644
--- a/libgthumb/thumb-cache.c
+++ b/libgthumb/thumb-cache.c
@@ -56,23 +56,18 @@ cache_get_nautilus_cache_name (const char *path)
char *parent;
char *resolved_parent;
char *resolved_path = NULL;
- GnomeVFSResult result;
GnomeVFSURI *uri;
char *uri_txt;
char *retval;
parent = remove_level_from_path (path);
- result = resolve_all_symlinks (parent, &resolved_parent);
+ resolved_parent = resolve_all_symlinks (parent);
g_free (parent);
- if (result == GNOME_VFS_OK)
- resolved_path = g_strconcat (resolved_parent,
- "/",
- file_name_from_path (path),
- NULL);
- else
- resolved_path = g_strdup (path);
-
+ resolved_path = g_strconcat (resolved_parent,
+ "/",
+ file_name_from_path (path),
+ NULL);
uri = new_uri_from_path (resolved_path);
g_free (resolved_path);
diff --git a/libgthumb/thumb-loader.c b/libgthumb/thumb-loader.c
index 661f288..c375590 100644
--- a/libgthumb/thumb-loader.c
+++ b/libgthumb/thumb-loader.c
@@ -29,7 +29,6 @@
#include <gtk/gtk.h>
#include <libgnomeui/gnome-thumbnail.h>
-#include <libgnomevfs/gnome-vfs-result.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "gthumb-init.h"
@@ -325,12 +324,8 @@ thumb_loader_set_file (ThumbLoader *tl,
tl->priv->file = file_data_dup (fd);
if (is_local_file (tl->priv->file->path)) {
char *resolved_path = NULL;
- if (resolve_all_symlinks (tl->priv->file->path, &resolved_path) == GNOME_VFS_OK)
- file_data_set_path (tl->priv->file, resolved_path);
- else {
- file_data_unref (tl->priv->file);
- tl->priv->file = NULL;
- }
+ resolved_path = resolve_all_symlinks (tl->priv->file->path);
+ file_data_set_path (tl->priv->file, resolved_path);
g_free (resolved_path);
}
}
diff --git a/src/dlg-search.c b/src/dlg-search.c
index 2135d45..8bacd6f 100644
--- a/src/dlg-search.c
+++ b/src/dlg-search.c
@@ -1043,13 +1043,12 @@ directory_load_cb (GnomeVFSAsyncHandle *handle,
break;
full_uri = gnome_vfs_uri_append_path (data->uri, info->name);
str_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
- if (resolve_all_symlinks (str_uri, &real_uri) == GNOME_VFS_OK) {
- if (g_hash_table_lookup (data->visited_dirs, real_uri) == NULL) {
- data->dirs = g_list_prepend (data->dirs, g_strdup (real_uri));
- g_hash_table_insert (data->visited_dirs, g_strdup (real_uri), GINT_TO_POINTER (1));
- }
- g_free (real_uri);
+ real_uri = resolve_all_symlinks (str_uri);
+ if (g_hash_table_lookup (data->visited_dirs, real_uri) == NULL) {
+ data->dirs = g_list_prepend (data->dirs, g_strdup (real_uri));
+ g_hash_table_insert (data->visited_dirs, g_strdup (real_uri), GINT_TO_POINTER (1));
}
+ g_free (real_uri);
g_free (str_uri);
break;
@@ -1119,10 +1118,7 @@ search_dir_async (DialogData *data,
gnome_vfs_uri_unref (data->uri);
uri = add_scheme_if_absent (dir);
- if (! resolve_all_symlinks (uri, &real_uri) == GNOME_VFS_OK) {
- g_free (uri);
- return;
- }
+ real_uri = resolve_all_symlinks (uri);
g_free (uri);
g_hash_table_insert (data->visited_dirs, g_strdup (real_uri), GINT_TO_POINTER (1));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]