[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] [PATCH] E Protected File Registry



Hi all,

I've attached some patches and additional files that add a protected
file registry to E. Basically, the point of this is to protect files
that are in use from being deleted by fm2 in its various guises.
The patch adds file protection for themes and desktops at the moment,
and works reliably. e_filereg.c and e_filereg.h go into e/src/bin (of
course :)).

Any suggestions gratefully accepted.

metrics
? src/bin/e_filereg.c
? src/bin/e_filereg.h
Index: src/bin/Makefile.am
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/Makefile.am,v
retrieving revision 1.157
diff -u -r1.157 Makefile.am
--- src/bin/Makefile.am	9 Oct 2006 19:06:43 -0000	1.157
+++ src/bin/Makefile.am	10 Oct 2006 06:30:55 -0000
@@ -174,7 +174,8 @@
 e_int_config_transitions.h \
 e_fwin.h \
 e_widget_aspect.h \
-e_widget_desk_preview.h
+e_widget_desk_preview.h \
+e_filereg.h
  
 enlightenment_src = \
 e_user.c \
@@ -325,6 +326,7 @@
 e_fwin.c \
 e_widget_aspect.c \
 e_widget_desk_preview.c \
+e_filereg.c \
 $(ENLIGHTENMENTHEADERS)
 
 enlightenment_SOURCES = \
Index: src/bin/e_bg.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_bg.c,v
retrieving revision 1.20
diff -u -r1.20 e_bg.c
--- src/bin/e_bg.c	9 Oct 2006 19:06:43 -0000	1.20
+++ src/bin/e_bg.c	10 Oct 2006 06:30:55 -0000
@@ -5,10 +5,27 @@
 
 /* local subsystem functions */
 static void _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source);
+static void _e_bg_register_files(void);
+static void _e_bg_deregister_files(void);
 
 /* local subsystem globals */
+static int _e_bg_reg_files = 0;
 
 /* externally accessible functions */
+EAPI int 
+e_bg_init(void)
+{
+   _e_bg_register_files();
+   return 1;
+}
+
+EAPI int 
+e_bg_shutdown(void)
+{
+   _e_bg_deregister_files();
+   return 1;
+}
+
 EAPI const char *
 e_bg_file_get(E_Zone *zone, E_Desk *desk)
 {
@@ -77,7 +94,7 @@
    Evas_Object *o;
    const char *bgfile = "";
    const char *trans = "";
-   
+
    if (transition == E_BG_TRANSITION_START) trans = e_config->transition_start;
    else if (transition == E_BG_TRANSITION_DESK) trans = e_config->transition_desk;
    else if (transition == E_BG_TRANSITION_CHANGE) trans = e_config->transition_change;
@@ -191,7 +208,7 @@
    E_Manager *man;
    E_Container *con;
    E_Zone *zone;
-   
+
    for (l = e_manager_list(); l; l = l->next)
      {
 	man = l->data;
@@ -205,6 +222,8 @@
 	       }
 	  }
      }
+
+   _e_bg_register_files();
 }
 
 /* local subsystem functions */
@@ -232,3 +251,55 @@
    evas_object_clip_set(zone->bg_object, zone->bg_clip_object);
    evas_object_show(zone->bg_object);
 }
+
+static void
+_e_bg_register_files(void)
+{
+   Evas_List *l;
+   const char * bgfile = "";
+   int i = 0, j;
+   char buf[256];
+   
+   if (e_config->desktop_default_background)
+      e_filereg_register("bg/default", e_config->desktop_default_background);
+   else
+      e_filereg_deregister("bg/default");
+
+   for (l = e_config->desktop_backgrounds; l; l = l->next)
+     {
+	E_Config_Desktop_Background *cfbg;
+	cfbg = l->data;
+	bgfile = cfbg->file;
+	snprintf(buf, 256, "bg/desk/%d", i);
+        if (e_filereg_register(buf, bgfile))
+	  i++;
+     }
+
+   if (i < _e_bg_reg_files)
+     {
+	for (j = i; j < _e_bg_reg_files; j++)
+	  {
+	    snprintf(buf, 256, "bg/desk/%d", j);
+	    e_filereg_deregister(buf);
+	  }
+     }
+
+   _e_bg_reg_files = i;
+}
+
+static void
+_e_bg_deregister_files(void)
+{
+   int i = 0;
+   char buf[256];
+   
+   e_filereg_deregister("bg/default");
+
+   for (i = 0; i < _e_bg_reg_files; i++)
+     {
+	snprintf(buf, 256, "bg/desk/%d", i);
+	e_filereg_deregister(buf);
+     }
+
+   _e_bg_reg_files = 0;
+}
Index: src/bin/e_bg.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_bg.h,v
retrieving revision 1.6
diff -u -r1.6 e_bg.h
--- src/bin/e_bg.h	9 Oct 2006 19:06:43 -0000	1.6
+++ src/bin/e_bg.h	10 Oct 2006 06:30:55 -0000
@@ -14,6 +14,9 @@
 #ifndef E_BG_H
 #define E_BG_H
 
+EAPI int e_bg_init(void);
+EAPI int e_bg_shutdown(void);
+
 EAPI const char *e_bg_file_get(E_Zone *zone, E_Desk *desk);
 EAPI void e_bg_zone_update(E_Zone *zone, E_Bg_Transition transition);
 EAPI void e_bg_add(int container, int zone, int desk_x, int desk_y, char *file);
Index: src/bin/e_fm.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_fm.c,v
retrieving revision 1.85
diff -u -r1.85 e_fm.c
--- src/bin/e_fm.c	9 Oct 2006 13:43:35 -0000	1.85
+++ src/bin/e_fm.c	10 Oct 2006 06:30:58 -0000
@@ -4136,7 +4136,7 @@
    E_Manager *man;
    E_Container *con;
    E_Zone *zone;
-   int x, y, can_w, can_w2;
+   int x, y, can_w, can_w2, protected;
    char buf[4096];
    
    sd = ic->sd;
@@ -4221,7 +4221,11 @@
 	  snprintf(buf, sizeof(buf), "%s/.order", sd->realpath);
 	if (ecore_file_can_write(buf)) can_w = 1;
      }
-   if ((can_w) && (can_w2))
+   
+   snprintf(buf, sizeof(buf), "%s/%s", sd->realpath, ic->info.file);
+   protected = e_filereg_file_protected(buf);
+
+   if ((can_w) && (can_w2) && !(protected))
      {
 	mi = e_menu_item_new(mn);
 	e_menu_item_separator_set(mi, 1);
Index: src/bin/e_includes.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_includes.h,v
retrieving revision 1.134
diff -u -r1.134 e_includes.h
--- src/bin/e_includes.h	9 Oct 2006 19:06:43 -0000	1.134
+++ src/bin/e_includes.h	10 Oct 2006 06:30:58 -0000
@@ -149,5 +149,6 @@
 #include "e_int_config_transitions.h"
 #include "e_obj_dialog.h"
 #include "e_fwin.h"
+#include "e_filereg.h"
 #include "e_widget_aspect.h"
 #include "e_widget_desk_preview.h"
Index: src/bin/e_main.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_main.c,v
retrieving revision 1.190
diff -u -r1.190 e_main.c
--- src/bin/e_main.c	30 Sep 2006 04:49:31 -0000	1.190
+++ src/bin/e_main.c	10 Oct 2006 06:31:01 -0000
@@ -489,6 +489,13 @@
 	_e_main_shutdown(-1);
      }
    _e_main_shutdown_push(_e_main_dirs_shutdown);
+   /* setup file registry */
+   if (!e_filereg_init())
+     {
+	e_error_message_show(_("Enlightenment cannot set up its file registry system."));
+	_e_main_shutdown(-1);
+     }
+   _e_main_shutdown_push(e_filereg_shutdown);
    /* init config system */
    if (!e_config_init())
      {
@@ -553,6 +560,13 @@
 	_e_main_shutdown(-1);
      }
    _e_main_shutdown_push(e_theme_shutdown);
+   /* init desktop background system */
+   if (!e_bg_init())
+     {
+	e_error_message_show(_("Enlightenment cannot set up its desktop background system."));
+	_e_main_shutdown(-1);
+     }
+   _e_main_shutdown_push(e_bg_init);
    if (!((!e_config->show_splash) || (after_restart)))
      {
 	/* setup init status window/screen */
Index: src/bin/e_theme.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_theme.c,v
retrieving revision 1.24
diff -u -r1.24 e_theme.c
--- src/bin/e_theme.c	23 Aug 2006 14:00:31 -0000	1.24
+++ src/bin/e_theme.c	10 Oct 2006 06:31:01 -0000
@@ -271,6 +271,7 @@
 e_theme_file_set(const char *category, const char *file)
 {
    E_Theme_Result *res;
+   char buf[4096];
 
    if (group_cache)
      {
@@ -289,6 +290,9 @@
    res = calloc(1, sizeof(E_Theme_Result));
    res->file = evas_stringshare_add(file);
    mappings = evas_hash_add(mappings, category, res);
+
+   snprintf(buf, 4096, "theme/%s", category);
+   e_filereg_register(buf, file);
 }
 
 EAPI int
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/*
 * Implementation of a protected file registry. Any files that are
 * currently being used by E in core components should be registered
 * here and will be protected as best as E can. :)
 */

/* Local subsystem functions */
static Evas_Bool _e_filereg_match(Evas_Hash *hash, const char *key, void *data, void *fdata);
static Evas_Bool _e_filereg_free(Evas_Hash *hash, const char *key, void *data, void *fdata);

/* Local subsystem globals */
static Evas_Hash *_e_filereg = NULL;

typedef struct _Filereg_Cmp_Data Filereg_Cmp_Data;

struct _Filereg_Cmp_Data
{
   char * path;
   Evas_Bool found;
};

/* Externally accessible functions */
EAPI int
e_filereg_init(void)
{
   return 1;
}

EAPI int
e_filereg_shutdown(void)
{
   /* Delete all strings in the hash */
   evas_hash_foreach(_e_filereg, _e_filereg_free, NULL);
   evas_hash_free(_e_filereg);
}

EAPI int
e_filereg_register(char * key, const char * path)
{
   char * tmp = NULL;
   e_filereg_deregister(key);

   tmp = strdup(path);
   if (!tmp)
     return 0;

   _e_filereg = evas_hash_add(_e_filereg, key, tmp);
   if (evas_hash_alloc_error())
     {
	fprintf(stderr, "ERROR: File registry has allocation failed.\n");
	return 0;
     }

   return 1;
}

EAPI int
e_filereg_deregister(char * key)
{
   char * path;

   /* Delete the string */
   path = evas_hash_find(_e_filereg, key);
   if (path)
     {
	_e_filereg = evas_hash_del(_e_filereg, key, NULL);
	E_FREE(path);
     }
   return 1;
}

EAPI Evas_Bool
e_filereg_file_protected(const char * path)
{
   Filereg_Cmp_Data arg;
   if (!_e_filereg) return 0;

   arg.found = 0;
   arg.path = path;
   evas_hash_foreach(_e_filereg, _e_filereg_match, &arg);

   return arg.found;
}

Evas_Bool 
_e_filereg_match(Evas_Hash *hash, const char *key, void *data, void *fdata) 
{
   Filereg_Cmp_Data * a;

   a = (Filereg_Cmp_Data *)fdata;
   if (!strcmp((char *)data, a->path))
     {
	a->found = 1;	
	return 0;	/* Stop searching */
     }
   else
     return 1;
}

Evas_Bool
_e_filereg_free(Evas_Hash *hash, const char *key, void *data, void *fdata) 
{
   E_FREE(data);
}

/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#ifdef E_TYPEDEFS

#else
#ifndef E_FILEREG_H
#define E_FILEREG_H

EAPI int e_filereg_init(void);
EAPI int e_filereg_shutdown(void);

EAPI int e_filereg_register(char * key, const char * path);
EAPI int e_filereg_deregister(char * key);
EAPI Evas_Bool e_filereg_file_protected(const char * path);

#endif
#endif