+bundle_util_file_insert(): Glue for autogenerated bundle files.
authorshort <>
Thu, 7 Jul 2005 04:53:04 +0000 (04:53 +0000)
committershort <>
Thu, 7 Jul 2005 04:53:04 +0000 (04:53 +0000)
Fixed error exceptions of bundled files write out.
Fixed attempt to remove bundled files even if not yet written out.

src/bundle-util.c

index 9200493..5149abf 100644 (file)
@@ -53,6 +53,24 @@ const guint8 *data;
        return data;
 }
 
+void bundle_util_file_insert(const void *data,gsize data_length,const gchar *basename)
+{
+guint8 *buffer;
+
+       g_return_if_fail(data!=NULL);
+       g_return_if_fail(basename!=NULL);
+
+       if (optarg_verbose)
+               g_message(_("Internally storing autogenerated: %s"),basename);
+       udpgate_newn(buffer,sizeof(guint32)+data_length);
+       *((guint32 *)buffer)=GUINT32_TO_BE(data_length);
+       g_assert(data_length==GUINT32_FROM_BE(*(guint32 *)buffer));
+       memcpy(buffer+sizeof(data_length),data,data_length);
+       /* FIXME: Missing duplicity check! */
+       /* FIXME: Missing g_free() on the element removal! */
+       g_hash_table_insert(bundle_hash_new(),g_strdup(basename),buffer);
+}
+
 /* Returns TRUE if it safe to overwrite/unlink the file.
  */
 static gboolean bundle_util_file_backup_conditional(const gchar *pathname,const gchar *basename)
@@ -226,7 +244,6 @@ mode_t dir_mode=pathname_mode;
 
        if (flags&BUNDLE_UTIL_TEMPORARY_MASK) {
 struct dir_stack **mkdirs_tail_pointer;
-struct file_stack *file_stack;
 
                /* Stack current 'mkdirs' in front of the current: bundle_util_file_write_atexit_dir_stack_head
                 * to remove them in the reverse order than created.
@@ -237,6 +254,20 @@ struct file_stack *file_stack;
                *mkdirs_tail_pointer=bundle_util_file_write_atexit_dir_stack_head;
                bundle_util_file_write_atexit_dir_stack_head=mkdirs;
                mkdirs=NULL;
+               }
+       /* Currently just unsupported: */
+       g_assert(!mkdirs);
+
+       if (-1==(fd=open(pathname,O_WRONLY|O_CREAT|O_TRUNC,pathname_mode))) {
+               if (errno!=EACCES)
+                       g_warning(_("Error opening the file \"%s\" for rewrite: %m"),pathname);
+               return FALSE;
+               }
+       /* Register the file only if it got already created.
+        * Do not atempt to remove files which are not ours!
+        */
+       if (flags&BUNDLE_UTIL_TEMPORARY_MASK) {
+struct file_stack *file_stack;
 
                /* Register also the file itself. */
                udpgate_new(file_stack);
@@ -245,14 +276,7 @@ struct file_stack *file_stack;
                file_stack->next=bundle_util_file_write_atexit_file_stack_head;
                bundle_util_file_write_atexit_file_stack_head=file_stack;
                }
-       /* Currently just unsupported: */
-       g_assert(!mkdirs);
 
-       if (-1==(fd=open(pathname,O_WRONLY|O_CREAT|O_TRUNC,pathname_mode))) {
-               if (errno!=EPERM)
-                       g_warning(_("Error opening the file \"%s\" for rewrite: %m"),pathname);
-               return FALSE;
-               }
        if ((int)data_length!=write(fd,data,data_length)) {
                g_warning(_("Error writing the data of the file \"%s\" being overwritten: %m"),pathname);
                close(fd);      /* errors ignored */