.SH NOTES
-The WIM file is rebuilt with all unnecessary file data removed. This is
-different from Microsoft's imagex.exe, which only will delete the directory tree
-metadata and XML data for this operation.
+By default, the WIM file is rebuilt with all unnecessary file data removed.
+This is different from Microsoft's imagex.exe, which only will delete the
+directory tree metadata and XML data for this operation. (See the \fB--soft\fR
+option for the other kind of delete).
Also, unlike imagex.exe, it is legal to delete all the images from a WIM and
have a WIM with 0 images, although such a file wouldn't be very useful.
present; additionally, when rewriting \fIWIMFILE\fR after the specified image was
deleted, write an integrity table. If this option is not specified, no integrity
table is included in the new WIM file, even if there was one before.
+.TP 6
+\fB--soft\fR
+Perform a "soft delete". Specifying this flag overrides the default behavior of
+rebuilding the entire WIM after deleting an image. Instead, only minimal
+changes to correctly remove the image from the WIM will be taken. In
+particular, all streams will be left alone, even if they are no longer
+referenced. This is probably not what you want, because almost no space will be
+saved by deleting an image in this way.
+
+You may use \fBimagex optimize\fR to delete unreferenced streams from a WIM that
+has had images soft-deleted from it.
.SH EXAMPLES
Delete the first image from 'boot.wim':
" [--flags EDITION_ID] [--verbose] [--dereference]\n"
" [--config=FILE] [--threads=NUM_THREADS]\n",
[DELETE] =
-"imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n",
+"imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check] [--soft]\n",
[DIR] =
"imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all)\n",
[EXPORT] =
};
static const struct option delete_options[] = {
{"check", no_argument, NULL, 'c'},
+ {"soft", no_argument, NULL, 's'},
{NULL, 0, NULL, 0},
};
open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
break;
+ case 's':
+ write_flags |= WIMLIB_WRITE_FLAG_SOFT_DELETE;
+ break;
default:
usage(DELETE);
return -1;
if (lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA) {
if (w->current_image == w->hdr.image_count) {
- ERROR("Expected only %u images, but found more",
+ ERROR("The WIM header says there are %u images in the WIM,\n"
+ " but we found more metadata resources than this",
w->hdr.image_count);
ret = WIMLIB_ERR_IMAGE_COUNT;
} else {
* same. Instead, recompress them. */
#define WIMLIB_WRITE_FLAG_RECOMPRESS 0x00000020
+/** Specifying this flag overrides the default behavior of wimlib_overwrite()
+ * after one or more calls to wimlib_delete_image(), which is to rebuild the
+ * entire WIM. If you specifiy this flag to wimlib_overwrite() instead, only
+ * minimal changes to correctly remove the image from the WIM will be taken. In
+ * particular, all streams will be left alone, even if they are no longer
+ * references. This is probably not what you want, because almost no space will
+ * be spaced by deleting an image in this way. */
+#define WIMLIB_WRITE_FLAG_SOFT_DELETE 0x00000040
+
/** Mark the image being added as the bootable image of the WIM. */
#define WIMLIB_ADD_IMAGE_FLAG_BOOT 0x00000001
unsigned num_threads);
/**
- * This function is deprecated; call wimlib_overwrite() without the
- * WIMLIB_WRITE_FLAG_REBUILD flag instead.
+ * This function is deprecated; call wimlib_overwrite() instead.
+ * (wimlib_overwrite() no longer rebuilds the full WIM unless it has to or is
+ * specified explicitly with ::WIMLIB_WRITE_FLAG_REBUILD)
*/
extern int wimlib_overwrite_xml_and_header(WIMStruct *wim, int write_flags);
if (!w || !path)
return WIMLIB_ERR_INVALID_PARAM;
+ write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
+
if (image != WIM_ALL_IMAGES &&
(image < 1 || image > w->hdr.image_count))
return WIMLIB_ERR_INVALID_IMAGE;
if (ret != 0)
return ret;
- if (modified_image_idx == w->hdr.image_count) {
- /* If no images are modified, a new lookup table does not need
- * to be written. */
+ if (modified_image_idx == w->hdr.image_count && !w->deletion_occurred) {
+ /* If no images have been modified and no images have been
+ * deleted, a new lookup table does not need to be written. */
wimlib_assert(list_empty(&stream_list));
old_wim_end = w->hdr.lookup_table_res_entry.offset +
w->hdr.lookup_table_res_entry.size;
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
- if (!w->deletion_occurred && !(write_flags & WIMLIB_WRITE_FLAG_REBUILD)) {
+ if ((!w->deletion_occurred || (write_flags & WIMLIB_WRITE_FLAG_SOFT_DELETE))
+ && !(write_flags & WIMLIB_WRITE_FLAG_REBUILD))
+ {
int i, modified_image_idx;
for (i = 0; i < w->hdr.image_count && !w->image_metadata[i].modified; i++)
;