From a9ca8eed486e1a1deb479643ce00a149a93b0f38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Fri, 4 Mar 2016 04:21:18 +0100
Subject: setupapi: Ignore deletion of added files in SetupAddToDiskSpaceList.

---
 dlls/setupapi/diskspace.c       |  6 +++++
 dlls/setupapi/tests/diskspace.c | 60 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/dlls/setupapi/diskspace.c b/dlls/setupapi/diskspace.c
index 378aa59d..0cadf72 100644
--- a/dlls/setupapi/diskspace.c
+++ b/dlls/setupapi/diskspace.c
@@ -373,6 +373,12 @@ BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile,
 
         list_add_tail(&list->files, &file->entry);
     }
+    else if (operation == FILEOP_DELETE)
+    {
+        /* delete operations for added files are ignored */
+        ret = TRUE;
+        goto done;
+    }
 
     file->operation = operation;
     if (operation == FILEOP_COPY)
diff --git a/dlls/setupapi/tests/diskspace.c b/dlls/setupapi/tests/diskspace.c
index 60087d1..793d3a1 100644
--- a/dlls/setupapi/tests/diskspace.c
+++ b/dlls/setupapi/tests/diskspace.c
@@ -440,7 +440,15 @@ static void test_SetupQuerySpaceRequiredOnDriveA(void)
 
     ret = SetupQuerySpaceRequiredOnDriveA(handle, "F:", &space, NULL, 0);
     ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
-    ok(space == 0x200000, "Expected 0x100000 as required space, got %s\n", debugstr_longlong(space));
+    ok(space == 0x200000, "Expected 0x200000 as required space, got %s\n", debugstr_longlong(space));
+
+    snprintf(tmp, MAX_PATH, "F:\\wine-test-should-not-exist.txt");
+    ret = SetupAddToDiskSpaceListA(handle, tmp, 0x200000, FILEOP_DELETE, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+
+    ret = SetupQuerySpaceRequiredOnDriveA(handle, "F:", &space, NULL, 0);
+    ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
+    ok(space == 0x200000, "Expected 0x200000 as required space, got %s\n", debugstr_longlong(space));
 
     ok(SetupDestroyDiskSpaceList(handle),
        "Expected SetupDestroyDiskSpaceList to succeed\n");
@@ -478,6 +486,45 @@ static void test_SetupQuerySpaceRequiredOnDriveA(void)
     ok(SetupDestroyDiskSpaceList(handle),
        "Expected SetupDestroyDiskSpaceList to succeed\n");
 
+    /* test FILEOP_DELETE, then FILEOP_COPY */
+    handle = SetupCreateDiskSpaceListA(NULL, 0, 0);
+    ok(handle != NULL,
+       "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n");
+
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_DELETE, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_COPY, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+
+    space = 0;
+    ret = SetupQuerySpaceRequiredOnDriveA(handle, drive, &space, NULL, 0);
+    ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
+    ok(space == 0 || broken(space == -0x5000) || broken(space == -0x7000),
+       "Expected 0x0 as required space, got %s\n", debugstr_longlong(space));
+
+    ok(SetupDestroyDiskSpaceList(handle),
+       "Expected SetupDestroyDiskSpaceList to succeed\n");
+
+    /* test FILEOP_COPY, then FILEOP_DELETE */
+    handle = SetupCreateDiskSpaceListA(NULL, 0, 0);
+    ok(handle != NULL,
+       "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n");
+
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_COPY, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_DELETE, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+
+    space = 0;
+    ret = SetupQuerySpaceRequiredOnDriveA(handle, drive, &space, NULL, 0);
+    ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
+    ok(space == 0 || broken(space == -0x5000) || broken(space == -0x7000),
+       "Expected 0x0 as required space, got %s\n", debugstr_longlong(space));
+
+    ok(SetupDestroyDiskSpaceList(handle),
+       "Expected SetupDestroyDiskSpaceList to succeed\n");
+
+    /* test FILEOP_DELETE without SPDSL_IGNORE_DISK */
     handle = SetupCreateDiskSpaceListA(NULL, 0, 0);
     ok(handle != NULL,
        "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n");
@@ -492,6 +539,7 @@ static void test_SetupQuerySpaceRequiredOnDriveA(void)
     ok(SetupDestroyDiskSpaceList(handle),
        "Expected SetupDestroyDiskSpaceList to succeed\n");
 
+    /* test FILEOP_COPY and FILEOP_DELETE with SPDSL_IGNORE_DISK */
     handle = SetupCreateDiskSpaceListA(NULL, 0, SPDSL_IGNORE_DISK);
     ok(handle != NULL,
        "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n");
@@ -503,6 +551,16 @@ static void test_SetupQuerySpaceRequiredOnDriveA(void)
     ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
     ok(space == 0, "Expected size = 0, got %s\n", debugstr_longlong(space));
 
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_COPY, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+    ret = SetupAddToDiskSpaceListA(handle, tmp, size, FILEOP_DELETE, 0, 0);
+    ok(ret, "Expected SetupAddToDiskSpaceListA to succeed\n");
+
+    space = 0;
+    ret = SetupQuerySpaceRequiredOnDriveA(handle, drive, &space, NULL, 0);
+    ok(ret, "Expected SetupQuerySpaceRequiredOnDriveA to succeed\n");
+    ok(space >= size, "Expected size >= %s\n", debugstr_longlong(space));
+
     ok(SetupDestroyDiskSpaceList(handle),
        "Expected SetupDestroyDiskSpaceList to succeed\n");
 }
-- 
2.7.1

