Subversion Repositories pub

Compare Revisions

Ignore whitespace Rev 4 → Rev 1

/nautilus-follow-symlink/trunk/src/Makefile.am
File deleted
/nautilus-follow-symlink/trunk/src/Makefile
0,0 → 1,57
 
# Note that building without FINAL=1 creates an uber-verbose version
 
ifneq ($(FINAL),1)
VERSION:=\"0.5.1.interim.debug\"
else
VERSION:=\"0.5.1\"
endif
 
CFLAGS=$$(pkg-config --cflags glib-2.0 libnautilus-extension)
LDFLAGS=$$(pkg-config --libs glib-2.0 libnautilus-extension)
 
CFLAGS+=-DPIC -fPIC -g -O -DVERSION=$(VERSION)
LDFLAGS+=-Wl,--as-needed -g -O
 
ifneq ($(FINAL),1)
CFLAGS+=-D_DEBUG
endif
 
TARGET=libnautilus-follow-symlink
 
# REQUIRED TO BUILD!
TARGET_DIR=/usr/lib/nautilus/extensions-1.0
INSTALL_DIR=$(DESTDIR)$(TARGET_DIR)
 
CC:=gcc
 
all: $(TARGET).so
 
$(TARGET).la: follow-symlink.o nautilus-ext-follow-symlink.o
libtool --mode=link $(CC) $(LDFLAGS) -o $(TARGET).la follow-symlink.lo nautilus-ext-follow-symlink.lo -rpath $(TARGET_DIR)
 
$(TARGET).so: $(TARGET).la
ln -sf .libs/$(TARGET).so .
 
follow-symlink.o: follow-symlink.c follow-symlink.h common.h
libtool --mode=compile $(CC) $(CFLAGS) -c follow-symlink.c
 
nautilus-ext-follow-symlink.o: nautilus-ext-follow-symlink.c nautilus-ext-follow-symlink.h common.h
libtool --mode=compile $(CC) $(CFLAGS) -c nautilus-ext-follow-symlink.c
 
install: strip
mkdir -p $(INSTALL_DIR)
install -m644 -oroot -groot $(TARGET).so $(INSTALL_DIR)/
 
uninstall:
rm -f $(INSTALL_DIR)/$(TARGET).so
rmdir -p $(INSTALL_DIR) || true
 
strip: $(TARGET).so
strip $(TARGET).so
 
distclean: clean
 
clean:
rm -f *.la *.lo *.o *.so
rm -rf .libs
/nautilus-follow-symlink/trunk/src/common.h
1,53 → 1,17
#ifndef FOLLOW_SYMLINK_COMMON_H
#define FOLLOW_SYMLINK_COMMON_H
 
/*
* This file defines common debug utilities.
* Also, includes config.h.
*/
#include <glib.h>
 
#include <glib/gmessages.h> /* g_print() */
#include <glib/gprintf.h> /* g_printf() */
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
 
#ifdef _DEBUG
/* Debugging facilities */
#include <stdlib.h> /* getenv() (3) */
#include <string.h> /* strcmp() (3) */
 
/* Prefix for messages */
#define FSL_ "nautilus-follow-symlink: "
/* Environment variable, set to 1 to enable verbosity */
#define DBGENV_ (getenv("FSL_DBG"))
/* Check on runtime the environment variable's value */
#define DEBUG_ON_() (DBGENV_ != NULL && 0 == strcmp(DBGENV_,"1"))
 
/* Informational message shown on initialisation */
#define FSL_DEBUG_INIT() { \
const int ENABLED = DEBUG_ON_(); \
g_print( FSL_ "DEBUG mode is available, and "); \
g_print( (ENABLED) ? "enabled.\n" : "disabled.\n"); \
g_print( FSL_ "set the environment variable FSL_DBG to \n" \
FSL_ "1 to enable it or to any other value to disable it.\n"); \
};
 
/* Display the name of the current function name */
#define TRACE() if (DEBUG_ON_())\
g_printf("nautilus-follow-symlink trace: %s()\n", __FUNCTION__);
/* Display a message */
#define FSL_LOG(str) if (DEBUG_ON_()) g_printf("%s\n", (str));
/* Display a formatted message with one string argument */
#define FSL_LOG1(str1, str2) if (DEBUG_ON_()) g_printf("%s %s\n", (str1), (str2));
#define TRACE() (g_printf("nautilus-follow-symlink trace: %s()\n", __FUNCTION__));
#else
/* Debugging facilities disabled */
#define TRACE()
#define FSL_LOG(a)
#define FSL_LOG1(a,b)
#define FSL_DEBUG_INIT()
#define TRACE()
#endif
 
#ifndef VERSION
#define VERSION "interim.debug"
#endif
 
#endif /* FOLLOW_SYMLINK_COMMON_H */
/* vim:set ts=4 et ai: */
/nautilus-follow-symlink/trunk/src/follow-symlink.c
1,15 → 1,5
#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)
{
32,8 → 22,7
// Number of files = g_list_length(files)
// Directory = nautilus_file_info_is_directory(files->data)
 
if (NULL==files || g_list_length(files) != 1) {
FSL_LOG( (NULL==files) ? "No file" : "More than one file" );
if (files == NULL || g_list_length(files) != 1) {
return NULL;
}
 
41,7 → 30,6
{
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);
57,7 → 45,6
*/
/*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
64,11 → 51,9
// TODO: Has glib/gnome any better/faster alternatives?
{
struct stat file_info;
// Note ..._get_name doesn't give the full path
const gchar * const file_name = nautilus_file_info_get_uri(files->data) + URI_OFFSET;
const gchar * const file_name = nautilus_file_info_get_name(files->data);
lstat(file_name, &file_info);
if (! S_ISLNK(file_info.st_mode)) {
FSL_LOG1( "Not S_ISLNK:", file_name );
return NULL;
}
}
84,33 → 69,32
{
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) + URI_OFFSET;
const gchar * link_name = nautilus_file_info_get_uri(file_info);
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, target)) {
g_printf("ERROR in realpath(): %s\n", strerror(errno));
if (NULL == realpath(link_name + URI_OFFSET, target)) {
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) + 2 ) );
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) );
 
gchar * offset = g_stpcpy(command_line, BASE_CMD);
//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, "\"");
offset = g_stpcpy(offset, "file://");
g_stpcpy(offset, target);
 
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,
/nautilus-follow-symlink/trunk/src/nautilus-ext-follow-symlink.c
1,7 → 1,5
#include "nautilus-ext-follow-symlink.h"
 
#include <glib/gprintf.h>
 
/* Public interface */
static GType fsl_type;
static GType provider_types[1];
9,7 → 7,6
void nautilus_module_initialize (GTypeModule *module)
{
TRACE();
FSL_DEBUG_INIT();
 
g_printf("Initializing nautilus-follow-symlink extension (v.%s)\n", VERSION);
 
73,12 → 70,12
return fsl_type;
}
 
void fsl_instance_init(FsymlinkExtension *cvs)
static void fsl_instance_init(FsymlinkExtension *cvs)
{
TRACE();
}
 
void fsl_class_init(FsymlinkExtensionClass *class)
static void fsl_class_init(FsymlinkExtensionClass *class)
{
TRACE();
}
/nautilus-follow-symlink/trunk/src/follow-symlink.h
7,11 → 7,18
*/
 
#include <libnautilus-extension/nautilus-menu-provider.h>
#include <sys/stat.h>
#include <stdlib.h> /* realpath() */
#include <string.h> /* strlen() */
 
#include "common.h"
 
/* Static Prototypes */
 
static GType fsl_get_type(void);
 
static void fsl_register_type(GTypeModule *);
 
static void fsl_callback(NautilusMenuItem *, NautilusFileInfo *);
 
static GList *fsl_get_file_items(NautilusMenuProvider *, GtkWidget *, GList *);