From 5efcc88199cf854e356ac8a3d47cf95e0252b7c1 Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Sat, 13 Aug 2005 13:49:54 +0000 Subject: [PATCH] r4098: Failure to create a usable default icon theme can be due to a broken link, so inform the user and show ~/.icons (Stephen Watson). Extended attribute support more general, not just types (Stephen Watson). --- ROX-Filer/Help/Changes | 3 ++ ROX-Filer/src/diritem.c | 2 +- ROX-Filer/src/infobox.c | 4 +- ROX-Filer/src/main.c | 5 +- ROX-Filer/src/menu.c | 4 +- ROX-Filer/src/type.c | 6 ++- ROX-Filer/src/xtypes.c | 137 ++++++++++++++++++++++++++++++------------------ ROX-Filer/src/xtypes.h | 18 ++++--- 8 files changed, 115 insertions(+), 64 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 8fe1e8a2..d8160e1f 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -5,6 +5,9 @@ 13-Aug-2005 ~~~~~~~~~~~ Removed GNOME-VFS from --version output; we never use it now (Thomas Leonard). +Failure to create a usable default icon theme can be due to a broken link, so +inform the user and show ~/.icons (Stephen Watson). +Extended attribute support more general, not just types (Stephen Watson). 12-Aug-2005 ~~~~~~~~~~~ diff --git a/ROX-Filer/src/diritem.c b/ROX-Filer/src/diritem.c index 6aac619c..942498c1 100644 --- a/ROX-Filer/src/diritem.c +++ b/ROX-Filer/src/diritem.c @@ -106,7 +106,7 @@ void diritem_restat(const guchar *path, DirItem *item, struct stat *parent) if (ABOUT_NOW(item->mtime) || ABOUT_NOW(item->ctime)) item->flags |= ITEM_FLAG_RECENT; - if (xtype_have_attr(path)) + if (xattr_have(path)) item->flags |= ITEM_FLAG_HAS_XATTR; if (S_ISLNK(info.st_mode)) diff --git a/ROX-Filer/src/infobox.c b/ROX-Filer/src/infobox.c index d5549858..432037e9 100644 --- a/ROX-Filer/src/infobox.c +++ b/ROX-Filer/src/infobox.c @@ -617,11 +617,11 @@ static GtkWidget *make_details(const guchar *path, DirItem *item, if (item->mime_type) add_row(store, "", mime_type_comment(item->mime_type)); - if (xtype_supported(NULL)) { + if (xattr_supported(NULL)) { add_row(store, _("Extended attributes:"), (item->flags & ITEM_FLAG_HAS_XATTR) ? _("Present") - : xtype_supported(path) ? _("None") + : xattr_supported(path) ? _("None") : _("Not supported")); } diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index e9d61fab..8bceca74 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -267,7 +267,7 @@ int main(int argc, char **argv) choices_init(); options_init(); i18n_init(); - xtype_init(); + xattr_init(); if (!app_dir) { @@ -685,6 +685,9 @@ static void show_features(void) _("No (apsymbols.h not found)") #endif ); + + g_print("%s... %s\n", _("Extended attribute support"), + xattr_supported(NULL)? _("Yes"): _("No")); } static void soap_add(xmlNodePtr body, diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index fe1e13b6..bed0380e 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -795,7 +795,7 @@ void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, ViewIter *iter) gtk_widget_set_sensitive(filer_follow_sym, strcmp(filer_window->sym_path, filer_window->real_path) != 0); gtk_widget_set_sensitive(filer_set_type, - xtype_supported(filer_window->real_path)); + xattr_supported(filer_window->real_path)); if (n_selected && o_menu_quick.int_value) popup_menu = (state & GDK_CONTROL_MASK) @@ -1022,7 +1022,7 @@ static void set_type_items(FilerWindow *filer_window) paths = filer_selected_items(filer_window); for(p=paths; p; p=g_list_next(p)) { - if(xtype_supported((const char *) p->data)) + if(xattr_supported((const char *) p->data)) npass++; else nfail++; diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index 65222197..c37ac769 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -1260,10 +1260,14 @@ static void set_icon_theme(void) icon_home = g_build_filename(home_dir, ".icons", "ROX", NULL); if (symlink(make_path(app_dir, "ROX"), icon_home)) + { delayed_error(_("Failed to create symlink '%s':\n%s\n\n" "(this may mean that the ROX theme already exists there, but " "the 'mime-application:postscript' icon couldn't be loaded for " - "some reason)"), icon_home, g_strerror(errno)); + "some reason, or %s is a link to an invalid directory)"), + icon_home, g_strerror(errno), icon_home); + open_to_show(icon_home); + } g_free(icon_home); gtk_icon_theme_rescan_if_needed(icon_theme); diff --git a/ROX-Filer/src/xtypes.c b/ROX-Filer/src/xtypes.c index 30a86809..3bc3eda0 100644 --- a/ROX-Filer/src/xtypes.c +++ b/ROX-Filer/src/xtypes.c @@ -59,7 +59,7 @@ static ssize_t (*dyn_getxattr)(const char *path, const char *name, static ssize_t (*dyn_listxattr)(const char *path, char *list, size_t size) = NULL; -void xtype_init(void) +void xattr_init(void) { void *libc; @@ -74,7 +74,7 @@ void xtype_init(void) option_add_int(&o_xattr_ignore, "xattr_ignore", FALSE); } -int xtype_supported(const char *path) +int xattr_supported(const char *path) { char buf[1]; ssize_t nent; @@ -95,7 +95,7 @@ int xtype_supported(const char *path) return TRUE; } -int xtype_have_attr(const char *path) +int xattr_have(const char *path) { char buf[1]; ssize_t nent; @@ -114,46 +114,47 @@ int xtype_have_attr(const char *path) return (nent>0); } -MIME_type *xtype_get(const char *path) +gchar *xattr_get(const char *path, const char *attr, int *len) { ssize_t size; gchar *buf; - MIME_type *type = NULL; RETURN_IF_IGNORED(NULL); if (!dyn_getxattr) return NULL; - size = dyn_getxattr(path, XTYPE_ATTR, "", 0); + size = dyn_getxattr(path, attr, "", 0); if (size > 0) { int new_size; buf = g_new(gchar, size + 1); - new_size = dyn_getxattr(path, XTYPE_ATTR, buf, size); + new_size = dyn_getxattr(path, attr, buf, size); - if (size == new_size) + if(size == new_size) { buf[size] = '\0'; - type = mime_type_lookup(buf); + + if(len) + *len=(int) size; + + return buf; } - g_free(buf); + g_free(buf); } - if (type) - return type; - /* Fall back to non-extended */ return NULL; + } /* 0 on success */ -int xtype_set(const char *path, const MIME_type *type) +int xattr_set(const char *path, const char *attr, + const char *value, int value_len) { int res; - gchar *ttext; - + if(o_xattr_ignore.int_value) { errno = ENOSYS; @@ -163,26 +164,26 @@ int xtype_set(const char *path, const MIME_type *type) if (!dyn_setxattr) { errno = ENOSYS; - return 1; /* Set type failed */ + return 1; /* Set attr failed */ } - ttext = g_strdup_printf("%s/%s", type->media_type, type->subtype); - res = dyn_setxattr(path, XTYPE_ATTR, ttext, strlen(ttext), 0); - g_free(ttext); + if(value && value_len<0) + value_len = strlen(value); - return res; + return dyn_setxattr(path, attr, value, value_len, 0); } + #elif defined(HAVE_ATTROPEN) /* Solaris 9 implementation */ -void xtype_init(void) +void xattr_init(void) { option_add_int(&o_xattr_ignore, "xattr_ignore", FALSE); } -int xtype_supported(const char *path) +int xattr_supported(const char *path) { RETURN_IF_IGNORED(FALSE); #ifdef _PC_XATTR_ENABLED @@ -195,7 +196,7 @@ int xtype_supported(const char *path) #endif } -int xtype_have_attr(const char *path) +int xattr_have(const char *path) { RETURN_IF_IGNORED(FALSE); #ifdef _PC_XATTR_EXISTS @@ -205,10 +206,11 @@ int xtype_have_attr(const char *path) #endif } -MIME_type *xtype_get(const char *path) +#define MAX_ATTR_SIZE BUFSIZ +gchar *xattr_get(const char *path, const char *attr, int *len); { int fd; - char buf[1024], *nl; + char *buf=NULL; int nb; MIME_type *type=NULL; @@ -219,31 +221,27 @@ MIME_type *xtype_get(const char *path) return NULL; #endif - fd=attropen(path, XTYPE_ATTR, O_RDONLY); + fd=attropen(path, attr, O_RDONLY); if(fd>=0) { - nb=read(fd, buf, sizeof(buf)); + buf = g_new(gchar, MAX_ATTR_SIZE); + nb=read(fd, buf, MAX_ATTR_SIZE); if(nb>0) { buf[nb]=0; - nl=strchr(buf, '\n'); - if(nl) - *nl=0; - type=mime_type_lookup(buf); } close(fd); + + if(len) + *len=nb; } - if(type) - return type; - - /* Fall back to non-extended */ - return NULL; + return buf; } -int xtype_set(const char *path, const MIME_type *type) +int xattr_set(const char *path, const char *attr, + const char *value, int value_len) { int fd; - gchar *ttext; int nb; if(o_xattr_ignore.int_value) @@ -252,14 +250,15 @@ int xtype_set(const char *path, const MIME_type *type) return 1; } - fd=attropen(path, XTYPE_ATTR, O_WRONLY|O_CREAT, 0644); + if(value && value_len<0) + value_len = strlen(value); + + fd=attropen(path, attr, O_WRONLY|O_CREAT, 0644); if(fd>0) { - ttext=g_strdup_printf("%s/%s", - type->media_type, type->subtype); - nb=write(fd, ttext, strlen(ttext)); - if(nb==strlen(ttext)) + + nb=write(fd, value, value_len); + if(nb==value_len) ftruncate(fd, (off_t) nb); - g_free(ttext); close(fd); @@ -273,27 +272,28 @@ int xtype_set(const char *path, const MIME_type *type) #else /* No extended attributes available */ -void xtype_init(void) +void xattr_init(void) { } -int xtype_supported(const char *path) +int xattr_supported(const char *path) { return FALSE; } -int xtype_have_attr(const char *path) +int xattr_have(const char *path) { return FALSE; } -MIME_type *xtype_get(const char *path) +gchar *xattr_get(const char *path, const char *attr, int *len) { /* Fall back to non-extended */ return NULL; } -int xtype_set(const char *path, const MIME_type *type) +int xattr_set(const char *path, const char *attr, + const char *value, int value_len) { errno = ENOSYS; return 1; /* Set type failed */ @@ -301,3 +301,40 @@ int xtype_set(const char *path, const MIME_type *type) #endif +MIME_type *xtype_get(const char *path) +{ + MIME_type *type = NULL; + gchar *buf; + char *nl; + + buf = xattr_get(path, XTYPE_ATTR, NULL); + + if(buf) + { + nl = strchr(buf, '\n'); + if(nl) + *nl = 0; + type = mime_type_lookup(buf); + g_free(buf); + } + return type; +} + +int xtype_set(const char *path, const MIME_type *type) +{ + int res; + gchar *ttext; + + if(o_xattr_ignore.int_value) + { + errno = ENOSYS; + return 1; + } + + ttext = g_strdup_printf("%s/%s", type->media_type, type->subtype); + res = xattr_set(path, XTYPE_ATTR, ttext, -1); + g_free(ttext); + + return res; +} + diff --git a/ROX-Filer/src/xtypes.h b/ROX-Filer/src/xtypes.h index e7d0fb32..0e4936a1 100644 --- a/ROX-Filer/src/xtypes.h +++ b/ROX-Filer/src/xtypes.h @@ -2,20 +2,24 @@ * ROX-Filer, filer for the ROX desktop project * By Thomas Leonard, . * - * Extended filesystem attribute support for MIME types + * Extended filesystem attribute support, particularly for MIME types */ #ifndef _XTYPES_H #define _XTYPES_H /* Prototypes */ -MIME_type *xtype_get(const char *path); -int xtype_set(const char *path, const MIME_type *type); -void xtype_init(void); - -int xtype_have_attr(const char *path); +void xattr_init(void); /* path may be NULL to test for support in libc */ -int xtype_supported(const char *path); +int xattr_supported(const char *path); + +int xattr_have(const char *path); +gchar *xattr_get(const char *path, const char *attr, int *len); +int xattr_set(const char *path, const char *attr, + const char *value, int value_len); + +MIME_type *xtype_get(const char *path); +int xtype_set(const char *path, const MIME_type *type); #endif -- 2.11.4.GIT