]> wimlib.net Git - wimlib/blobdiff - src/modify.c
Remove link_dentry()
[wimlib] / src / modify.c
index 5ff3bb3e1fde7dec7d421dd96e3e98da68131f80..7fc1a6cfe4f21eca877a581b0b5601a9a4aa3d85 100644 (file)
@@ -55,7 +55,7 @@ void destroy_image_metadata(struct image_metadata *imd, struct lookup_table *lt)
                lookup_table_remove(lt, imd->metadata_lte);
 }
 
-/* 
+/*
  * Recursively builds a dentry tree from a directory tree on disk, outside the
  * WIM file.
  *
@@ -63,10 +63,10 @@ void destroy_image_metadata(struct image_metadata *imd, struct lookup_table *lt)
  *             modified if successful.  NULL if the file or directory was
  *             excluded from capture.
  *
- * @root_disk_path:  The path to the root of the directory tree on disk. 
+ * @root_disk_path:  The path to the root of the directory tree on disk.
  *
  * @lookup_table: The lookup table for the WIM file.  For each file added to the
- *             dentry tree being built, an entry is added to the lookup table, 
+ *             dentry tree being built, an entry is added to the lookup table,
  *             unless an identical stream is already in the lookup table.
  *             These lookup table entries that are added point to the path of
  *             the file on disk.
@@ -128,7 +128,7 @@ static int build_dentry_tree(struct dentry **root_ret,
                return WIMLIB_ERR_STAT;
        }
 
-       if ((add_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) && 
+       if ((add_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) &&
              !S_ISDIR(root_stbuf.st_mode)) {
                ERROR("`%s' is not a directory", root_disk_path);
                return WIMLIB_ERR_NOTDIR;
@@ -196,13 +196,13 @@ static int build_dentry_tree(struct dentry **root_ret,
                        if (ret != 0)
                                break;
                        if (child)
-                               link_dentry(child, root);
+                               dentry_add_child(root, child);
                }
                closedir(dir);
        } else if (dentry_is_symlink(root)) { /* Archiving a symbolic link */
                char deref_name_buf[4096];
                ssize_t deref_name_len;
-               
+
                deref_name_len = readlink(root_disk_path, deref_name_buf,
                                          sizeof(deref_name_buf) - 1);
                if (deref_name_len >= 0) {
@@ -307,7 +307,7 @@ static int allocate_lte_if_needed(struct dentry *dentry, void *arg)
        return 0;
 }
 
-/* 
+/*
  * This function takes in a dentry that was previously located only in image(s)
  * in @src_wim, but now is being added to @dest_wim.  For each stream associated
  * with the dentry, if there is already a lookup table entry for that stream in
@@ -362,7 +362,7 @@ static int add_lte_to_dest_wim(struct dentry *dentry, void *arg)
 /*
  * Adds an image (given by its dentry tree) to the image metadata array of a WIM
  * file, adds an entry to the lookup table for the image metadata, updates the
- * image count in the header, and selects the new image. 
+ * image count in the header, and selects the new image.
  *
  * Does not update the XML data.
  *
@@ -389,15 +389,15 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry,
 
        if (!imd) {
                ERROR("Failed to allocate memory for new image metadata array");
-               return WIMLIB_ERR_NOMEM;
+               goto err;
        }
 
-       memcpy(imd, w->image_metadata, 
+       memcpy(imd, w->image_metadata,
               w->hdr.image_count * sizeof(struct image_metadata));
-       
+
        metadata_lte = new_lookup_table_entry();
        if (!metadata_lte)
-               goto out_free_imd;
+               goto err_free_imd;
 
        metadata_lte->resource_entry.flags = WIM_RESHDR_FLAG_METADATA;
        random_hash(metadata_lte->hash);
@@ -420,10 +420,9 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry,
        ret = select_wim_image(w, w->hdr.image_count);
        wimlib_assert(ret == 0);
        return ret;
-out_free_metadata_lte:
-       FREE(metadata_lte);
-out_free_imd:
+err_free_imd:
        FREE(imd);
+err:
        return WIMLIB_ERR_NOMEM;
 
 }
@@ -431,11 +430,11 @@ out_free_imd:
 /*
  * Copies an image, or all the images, from a WIM file, into another WIM file.
  */
-WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim, 
-                                 int src_image, 
-                                 WIMStruct *dest_wim, 
-                                 const char *dest_name, 
-                                 const char *dest_description, 
+WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
+                                 int src_image,
+                                 WIMStruct *dest_wim,
+                                 const char *dest_name,
+                                 const char *dest_description,
                                  int flags,
                                  WIMStruct **additional_swms,
                                  unsigned num_additional_swms)
@@ -461,7 +460,7 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
 
                        /* multi-image export. */
 
-                       if ((flags & WIMLIB_EXPORT_FLAG_BOOT) && 
+                       if ((flags & WIMLIB_EXPORT_FLAG_BOOT) &&
                              (src_wim->hdr.boot_idx == 0))
                        {
                                /* Specifying the boot flag on a multi-image
@@ -486,7 +485,7 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
                                if (i != src_wim->hdr.boot_idx)
                                        export_flags &= ~WIMLIB_EXPORT_FLAG_BOOT;
 
-                               ret = wimlib_export_image(src_wim, i, dest_wim, 
+                               ret = wimlib_export_image(src_wim, i, dest_wim,
                                                          NULL, NULL,
                                                          export_flags,
                                                          additional_swms,
@@ -495,8 +494,10 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
                                        return ret;
                        }
                        return 0;
+               } else if (src_wim->hdr.image_count == 1) {
+                       src_image = 1;
                } else {
-                       src_image = 1; 
+                       return 0;
                }
        }
 
@@ -600,8 +601,8 @@ out:
        return ret;
 }
 
-/* 
- * Deletes an image from the WIM. 
+/*
+ * Deletes an image from the WIM.
  */
 WIMLIBAPI int wimlib_delete_image(WIMStruct *w, int image)
 {
@@ -742,7 +743,7 @@ static int init_capture_config(const char *_config_str, size_t config_len,
                FREE(config_str);
                return WIMLIB_ERR_NOMEM;
        }
-       
+
        memcpy(config_str, _config_str, config_len);
        next_p = config_str;
        config->config_str = config_str;
@@ -758,7 +759,7 @@ static int init_capture_config(const char *_config_str, size_t config_len,
                        ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
                        goto out_destroy;
                }
-               
+
                next_p = eol + 1;
                bytes_remaining -= (next_p - p);
                if (eol == p)
@@ -887,7 +888,7 @@ bool exclude_path(const char *path, const struct capture_config *config,
                     && path[config->prefix_len] == '/')
                        path += config->prefix_len;
        }
-       return match_pattern(path, basename, &config->exclusion_list) && 
+       return match_pattern(path, basename, &config->exclusion_list) &&
                !match_pattern(path, basename, &config->exclusion_exception);
 
 }
@@ -910,7 +911,7 @@ int do_add_image(WIMStruct *w, const char *dir, const char *name,
                 const char *config_str, size_t config_len,
                 int flags,
                 int (*capture_tree)(struct dentry **, const char *,
-                                    struct lookup_table *, 
+                                    struct lookup_table *,
                                     struct wim_security_data *,
                                     const struct capture_config *,
                                     int, void *),
@@ -1007,7 +1008,7 @@ int do_add_image(WIMStruct *w, const char *dir, const char *name,
                goto out_destroy_imd;
 
        if (flags & WIMLIB_ADD_IMAGE_FLAG_BOOT)
-               wimlib_set_boot_idx(w, w->hdr.image_count);
+               w->hdr.boot_idx = w->hdr.image_count;
 
        return 0;
 out_destroy_imd:
@@ -1027,7 +1028,7 @@ out_destroy_config:
 /*
  * Adds an image to a WIM file from a directory tree on disk.
  */
-WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *dir, 
+WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *dir,
                               const char *name, const char *config_str,
                               size_t config_len, int flags)
 {