]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
wimlib_mount_image(): Delete staging dir on error paths
[wimlib] / src / mount_image.c
index d2ce94b215e36e1ab774a34cf90b12d07d71eb64..a05a822d10d78d0f2dc92b94076acdba5d7a36b4 100644 (file)
@@ -802,7 +802,7 @@ static int rebuild_wim(struct wimfs_context *ctx, int write_flags,
        }
 
        DEBUG("Calculating SHA1 checksums for all new staging files.");
        }
 
        DEBUG("Calculating SHA1 checksums for all new staging files.");
-       list_for_each_entry(lte, &ctx->staging_list, staging_list) {
+       list_for_each_entry_safe(lte, tmp, &ctx->staging_list, staging_list) {
                ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
                ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
@@ -2499,6 +2499,12 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
 
        if (ret)
                ret = WIMLIB_ERR_FUSE;
 
        if (ret)
                ret = WIMLIB_ERR_FUSE;
+
+       /* Try to delete the staging directory if a deletion wasn't yet
+        * attempted due to an earlier error */
+       if (ctx.staging_dir_name)
+               delete_staging_dir(&ctx);
+
 out_free_dir_copy:
        FREE(dir_copy);
 out_unlock:
 out_free_dir_copy:
        FREE(dir_copy);
 out_unlock: