1,5 → 1,15 |
#include "follow-symlink.h" |
|
#include <glib/gprintf.h> |
#include <sys/stat.h> |
#include <errno.h> /* errno (3) */ |
#include <stdlib.h> /* realpath() (3) */ |
#include <string.h> /* strlen(), strerror() (3) */ |
|
// Offset at char 7 to remove file:// |
static const unsigned short URI_OFFSET = 7 * sizeof(gchar); |
static const size_t PATH_LENGTH_BYTES = sizeof(gchar) * (PATH_MAX + 1); |
|
/* Menu initialization */ |
void fsl_extension_menu_provider_iface_init(NautilusMenuProviderIface *iface) |
{ |
22,7 → 32,8 |
// Number of files = g_list_length(files) |
// Directory = nautilus_file_info_is_directory(files->data) |
|
if (files == NULL || g_list_length(files) != 1) { |
if (NULL==files || g_list_length(files) != 1) { |
FSL_LOG( (NULL==files) ? "No file" : "More than one file" ); |
return NULL; |
} |
|
30,6 → 41,7 |
{ |
gchar * uri_scheme = nautilus_file_info_get_uri_scheme(files->data); |
if (strcmp(uri_scheme, "file") != 0) { |
FSL_LOG( "Not file scheme" ); |
return NULL; |
} |
g_free(uri_scheme); |
45,6 → 57,7 |
*/ |
/*if (gfi->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) {*/ |
if (gfi->type != GNOME_VFS_FILE_TYPE_DIRECTORY) { |
FSL_LOG( "Not directory" ); |
return NULL; |
} |
// We know the file is either a directory or a symlink to a directory |
51,9 → 64,11 |
// TODO: Has glib/gnome any better/faster alternatives? |
{ |
struct stat file_info; |
const gchar * const file_name = nautilus_file_info_get_name(files->data); |
// Note ..._get_name doesn't give the full path |
const gchar * const file_name = nautilus_file_info_get_uri(files->data) + URI_OFFSET; |
lstat(file_name, &file_info); |
if (! S_ISLNK(file_info.st_mode)) { |
FSL_LOG1( "Not S_ISLNK:", file_name ); |
return NULL; |
} |
} |
69,32 → 84,33 |
{ |
TRACE(); |
|
//g_print("fsl_callback\n"); |
const size_t URI_OFFSET = 7 * sizeof(gchar); // Offset at char 7 to remove file:// |
const size_t PATH_LENGTH_BYTES = sizeof(gchar) * (PATH_MAX + 1); |
gchar ** argv; |
const gchar * link_name = nautilus_file_info_get_uri(file_info); |
const gchar * link_name = nautilus_file_info_get_uri(file_info) + URI_OFFSET; |
gchar * target = g_malloc(PATH_LENGTH_BYTES); |
|
/* unlike readlink(man 2), realpath(man 3) resolves the symlink, while |
* readlink returns the pointed file, which might be a relative path |
* Xref: <http://www.gnu.org/software/libc/manual/html_node/Symbolic-Links.html> |
*/ |
if (NULL == realpath(link_name + URI_OFFSET, target)) { |
if (NULL == realpath(link_name, target)) { |
g_printf("ERROR in realpath(): %s\n", strerror(errno)); |
g_assert( FALSE ); |
} |
|
const gchar const * BASE_CMD = "nautilus --no-desktop --no-default-window "; |
gchar * command_line = g_malloc( sizeof(gchar) * (strlen(BASE_CMD) + strlen(target) + URI_OFFSET + 1) ); |
const gchar const * BASE_CMD = "nautilus --no-desktop --no-default-window \""; |
gchar * command_line = g_malloc( sizeof(gchar) * ( strlen(BASE_CMD) + strlen(target) + 2 ) ); |
|
gchar * offset = g_stpcpy(command_line, BASE_CMD); |
offset = g_stpcpy(offset, "file://"); |
g_stpcpy(offset, target); |
//offset = g_stpcpy(offset, "file://"); // unneeded; also makes nautilus think it may be incorrect |
// if it contains spaces (instead of %20's) |
offset = g_stpcpy(offset, target); |
g_stpcpy(offset, "\""); |
|
if (FALSE == g_shell_parse_argv(command_line, NULL, &argv, NULL)) { |
g_assert( FALSE ); |
} |
|
g_printf("nautilus-follow-symlink: Spawning nautilus with\n \"%s\"\n", command_line); |
g_printf("nautilus-follow-symlink: Spawning nautilus with\n '%s'\n", command_line); |
|
g_spawn_async( nautilus_file_info_get_parent_uri(file_info) + URI_OFFSET, |
argv, |