]> wimlib.net Git - wimlib/blobdiff - src/resource.c
Empty file fix
[wimlib] / src / resource.c
index 369ac453ac2611fc6bbced76582a588c8178a73d..e29434fc295bee0592bf09205ff0748b839f3ee6 100644 (file)
@@ -1038,10 +1038,12 @@ int write_metadata_resource(WIMStruct *w)
                return WIMLIB_ERR_WRITE;
 
        #ifdef ENABLE_SECURITY_DATA
-       subdir_offset = wim_security_data(w)->total_length + root->length + 8;
-       #else
-       subdir_offset = 8 + root->length + 8;
+       struct wim_security_data *sd = wim_security_data(w);
+       if (sd)
+               subdir_offset = sd->total_length + root->length + 8;
+       else
        #endif
+               subdir_offset = 8 + root->length + 8;
        calculate_subdir_offsets(root, &subdir_offset);
        metadata_original_size = subdir_offset;
        buf = MALLOC(metadata_original_size);
@@ -1052,7 +1054,7 @@ int write_metadata_resource(WIMStruct *w)
        }
        #ifdef ENABLE_SECURITY_DATA
        /* Write the security data. */
-       p = write_security_data(wim_security_data(w), buf);
+       p = write_security_data(sd, buf);
        #else
        p = put_u32(buf, 8); /* Total length of security data. */
        p = put_u32(p, 0); /* Number of security data entries. */
@@ -1110,8 +1112,6 @@ int write_file_resource(struct dentry *dentry, void *wim_p)
        struct lookup_table_entry *lte;
        int in_wim_ctype;
        int out_wim_ctype;
-       int input_res_ctype;
-       struct resource_entry *input_res_entry;
        struct resource_entry *output_res_entry;
        u64 len;
        int ret;
@@ -1136,6 +1136,10 @@ int write_file_resource(struct dentry *dentry, void *wim_p)
        out_wim_ctype = wimlib_get_compression_type(w);
        output_res_entry = &lte->output_resource_entry;
 
+       /* do not write empty resources */
+       if (lte->resource_entry.original_size == 0)
+               return 0;
+
        /* Figure out if we can read the resource from the WIM file, or
         * if we have to read it from the filesystem outside. */
        if (lte->file_on_disk) {
@@ -1173,15 +1177,14 @@ int write_file_resource(struct dentry *dentry, void *wim_p)
                        in = w->fp;
                        in_wim_ctype = out_wim_ctype;
                }
-               input_res_entry = &lte->resource_entry;
-               input_res_ctype = resource_compression_type(
+               int input_res_ctype = resource_compression_type(
                                        in_wim_ctype, 
-                                       input_res_entry->flags);
+                                       lte->resource_entry.flags);
 
                ret = transfer_file_resource(in, 
-                                       input_res_entry->size,
-                                       input_res_entry->original_size, 
-                                       input_res_entry->offset,
+                                       lte->resource_entry.size,
+                                       lte->resource_entry.original_size, 
+                                       lte->resource_entry.offset,
                                        input_res_ctype, 
                                        out, 
                                        out_wim_ctype,