X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdelete_image.c;h=9cbec0a2ef90ba8c6ce288bbdd0b70c085dfd967;hb=e3cbda91f4a1a844bc8edb5b5240b18f8261a6df;hp=442f8b609436f1c1c9c3e50eaa08c9eebaf2afc9;hpb=9a20d1f99bd5dcd22e55300a5e29748486e585d7;p=wimlib diff --git a/src/delete_image.c b/src/delete_image.c index 442f8b60..9cbec0a2 100644 --- a/src/delete_image.c +++ b/src/delete_image.c @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2012, 2013, 2014 Eric Biggers + * Copyright (C) 2012-2016 Eric Biggers * * This file is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free @@ -26,6 +26,7 @@ #include #include "wimlib.h" +#include "wimlib/dentry.h" #include "wimlib/metadata.h" #include "wimlib/wim.h" #include "wimlib/xml.h" @@ -36,17 +37,24 @@ int delete_wim_image(WIMStruct *wim, int image) { int ret; + struct wim_image_metadata *imd; /* Load the metadata for the image to be deleted. This is necessary - * because streams referenced by files in the image need to have their + * because blobs referenced by files in the image need to have their * reference counts decremented. */ ret = select_wim_image(wim, image); if (ret) return ret; - /* Release the reference to the image metadata and decrement reference - * counts on the streams referenced by files in the image. */ - put_image_metadata(wim->image_metadata[image - 1], wim->lookup_table); + /* Release the files and decrement the reference counts of the blobs + * they reference. */ + imd = wim->image_metadata[image - 1]; + free_dentry_tree(imd->root_dentry, wim->blob_table); + imd->root_dentry = NULL; + + /* Deselect the image and release its metadata. */ + deselect_current_wim_image(wim); + put_image_metadata(imd); /* Remove the empty slot from the image metadata array. */ memmove(&wim->image_metadata[image - 1], &wim->image_metadata[image], @@ -54,10 +62,10 @@ delete_wim_image(WIMStruct *wim, int image) sizeof(wim->image_metadata[0])); /* Decrement the image count. */ - --wim->hdr.image_count; + wim->hdr.image_count--; /* Remove the image from the XML information. */ - xml_delete_image(&wim->wim_info, image); + xml_delete_image(wim->xml_info, image); /* Fix the boot index. */ if (wim->hdr.boot_idx == image) @@ -65,8 +73,6 @@ delete_wim_image(WIMStruct *wim, int image) else if (wim->hdr.boot_idx > image) wim->hdr.boot_idx--; - /* The image is no longer valid. */ - wim->current_image = WIMLIB_NO_IMAGE; return 0; }