]> wimlib.net Git - wimlib/blobdiff - src/add_image.c
Move default capture config policy to library users
[wimlib] / src / add_image.c
index 4fc6c4a6cd0f3a778e7436110aac65a3152dfc4d..61ed013225ef696fc009228c2964eea3b2ea5d07 100644 (file)
@@ -46,14 +46,14 @@ int add_new_dentry_tree(WIMStruct *w, struct wim_dentry *root_dentry,
                        struct wim_security_data *sd)
 {
        struct wim_lookup_table_entry *metadata_lte;
-       struct image_metadata *imd;
-       struct image_metadata *new_imd;
+       struct wim_image_metadata *imd;
+       struct wim_image_metadata *new_imd;
 
        wimlib_assert(root_dentry != NULL);
 
        DEBUG("Reallocating image metadata array for image_count = %u",
              w->hdr.image_count + 1);
-       imd = CALLOC((w->hdr.image_count + 1), sizeof(struct image_metadata));
+       imd = CALLOC((w->hdr.image_count + 1), sizeof(struct wim_image_metadata));
 
        if (!imd) {
                ERROR("Failed to allocate memory for new image metadata array");
@@ -61,7 +61,7 @@ int add_new_dentry_tree(WIMStruct *w, struct wim_dentry *root_dentry,
        }
 
        memcpy(imd, w->image_metadata,
-              w->hdr.image_count * sizeof(struct image_metadata));
+              w->hdr.image_count * sizeof(struct wim_image_metadata));
 
        metadata_lte = new_lookup_table_entry();
        if (!metadata_lte)
@@ -91,8 +91,9 @@ err:
 
 
 /*
- * build_dentry_tree: - Recursively builds a tree of `struct wim_dentry tree
- *                     from an on-disk directory tree.
+ * build_dentry_tree():
+ *     Recursively builds a tree of WIM dentries from an on-disk directory
+ *     tree.
  *
  * @root_ret:   Place to return a pointer to the root of the dentry tree.  Only
  *             modified if successful.  Set to NULL if the file or directory was
@@ -229,10 +230,17 @@ static int build_dentry_tree(struct wim_dentry **root_ret,
        else
                inode->i_ino = (u64)root_stbuf.st_ino |
                                   ((u64)root_stbuf.st_dev << ((sizeof(ino_t) * 8) & 63));
-
-       add_image_flags &= ~WIMLIB_ADD_IMAGE_FLAG_ROOT;
        inode->i_resolved = 1;
-
+       if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
+               ret = inode_set_unix_data(inode, root_stbuf.st_uid,
+                                         root_stbuf.st_gid,
+                                         root_stbuf.st_mode,
+                                         lookup_table,
+                                         UNIX_DATA_ALL | UNIX_DATA_CREATE);
+               if (ret)
+                       goto out;
+       }
+       add_image_flags &= ~WIMLIB_ADD_IMAGE_FLAG_ROOT;
        if (S_ISREG(root_stbuf.st_mode)) { /* Archiving a regular file */
 
                struct wim_lookup_table_entry *lte;
@@ -388,8 +396,13 @@ enum pattern_type {
        ALIGNMENT_LIST,
 };
 
+#define COMPAT_DEFAULT_CONFIG
+
 /* Default capture configuration file when none is specified. */
 static const char *default_config =
+#ifdef COMPAT_DEFAULT_CONFIG /* XXX: This policy is being moved to library
+                               users.  The next ABI-incompatible library
+                               version will default to the empty string here. */
 "[ExclusionList]\n"
 "\\$ntfs.log\n"
 "\\hiberfil.sys\n"
@@ -403,6 +416,9 @@ static const char *default_config =
 "*.zip\n"
 "*.cab\n"
 "\\WINDOWS\\inf\\*.pnf\n";
+#else
+"";
+#endif
 
 static void destroy_pattern_list(struct pattern_list *list)
 {
@@ -575,21 +591,6 @@ static bool match_pattern(const char *path, const char *path_basename,
        return false;
 }
 
-static void print_pattern_list(const struct pattern_list *list)
-{
-       for (size_t i = 0; i < list->num_pats; i++)
-               printf("    %s\n", list->pats[i]);
-}
-
-static void print_capture_config(const struct capture_config *config)
-{
-       if (config->exclusion_list.num_pats) {
-               puts("Files or folders excluded from image capture:");
-               print_pattern_list(&config->exclusion_list);
-               putchar('\n');
-       }
-}
-
 /* Return true if the image capture configuration file indicates we should
  * exclude the filename @path from capture.
  *
@@ -629,15 +630,20 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source,
        struct wim_dentry *root_dentry = NULL;
        struct wim_security_data *sd;
        struct capture_config config;
-       struct image_metadata *imd;
+       struct wim_image_metadata *imd;
        int ret;
 
        if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_NTFS) {
 #ifdef WITH_NTFS_3G
-               if (add_image_flags & (WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)) {
+               if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE) {
                        ERROR("Cannot dereference files when capturing directly from NTFS");
                        return WIMLIB_ERR_INVALID_PARAM;
                }
+               if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
+                       ERROR("Capturing UNIX owner and mode not supported "
+                             "when capturing directly from NTFS");
+                       return WIMLIB_ERR_INVALID_PARAM;
+               }
                capture_tree = build_dentry_tree_ntfs;
                extra_arg = &w->ntfs_vol;
 #else
@@ -681,7 +687,6 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source,
        ret = init_capture_config(config_str, config_len, source, &config);
        if (ret != 0)
                return ret;
-       print_capture_config(&config);
 
        DEBUG("Allocating security data");