From af86bdc31b59c68ea218d6fcdb794e7c3ae74d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20Kentt=C3=A4?= Date: Sat, 4 Feb 2017 14:24:49 +0200 Subject: [PATCH] cabinet: Make Extract overwrite existing files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only read-only files must not be overwritten. Signed-off-by: Lauri Kenttä Signed-off-by: Alexandre Julliard --- dlls/cabinet/cabinet_main.c | 2 +- dlls/cabinet/tests/extract.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dlls/cabinet/cabinet_main.c b/dlls/cabinet/cabinet_main.c index 5a1ae06c291..239849d3552 100644 --- a/dlls/cabinet/cabinet_main.c +++ b/dlls/cabinet/cabinet_main.c @@ -251,7 +251,7 @@ static INT_PTR CDECL fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICAT } hFile = CreateFileA(szFullPath, GENERIC_READ | GENERIC_WRITE, 0, NULL, - CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) hFile = 0; diff --git a/dlls/cabinet/tests/extract.c b/dlls/cabinet/tests/extract.c index 849d612db12..d39043fb1cc 100644 --- a/dlls/cabinet/tests/extract.c +++ b/dlls/cabinet/tests/extract.c @@ -80,6 +80,18 @@ static void createTestFile(const CHAR *name) CloseHandle(file); } +static int getFileSize(const CHAR *name) +{ + HANDLE file; + int size; + file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); + if (file == INVALID_HANDLE_VALUE) + return -1; + size = GetFileSize(file, NULL); + CloseHandle(file); + return size; +} + static void create_test_files(void) { int len; @@ -621,9 +633,10 @@ static void test_Extract(void) ok(!check_list(&node, "a.txt", FALSE), "list entry should not exist\n"); free_file_list(&session); - /* first file exists */ + /* first file exists but is read-only */ createTestFile("dest\\a.txt"); SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_READONLY); + ok(getFileSize("dest\\a.txt") == 11, "Expected dest\\a.txt to be 11 bytes\n"); ZeroMemory(&session, sizeof(SESSION)); lstrcpyA(session.Destination, "dest"); session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES; @@ -647,7 +660,8 @@ static void test_Extract(void) ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination); ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved); ok(!session.FilterList, "Expected empty filter list\n"); - ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n"); + ok(getFileSize("dest\\a.txt") == 11, "Expected dest\\a.txt to be 11 bytes\n"); + ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to be read-only\n"); todo_wine { ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n"); @@ -663,7 +677,8 @@ static void test_Extract(void) SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_NORMAL); DeleteFileA("dest\\a.txt"); - /* third file exists */ + /* first file exists and is writable, third file exists but is read-only */ + createTestFile("dest\\a.txt"); createTestFile("dest\\testdir\\c.txt"); SetFileAttributesA("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY); ZeroMemory(&session, sizeof(SESSION)); @@ -689,9 +704,10 @@ static void test_Extract(void) ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination); ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved); ok(!session.FilterList, "Expected empty filter list\n"); + ok(getFileSize("dest\\a.txt") == 6, "Expected dest\\a.txt to be 6 bytes\n"); ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n"); ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n"); - ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n"); + ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to be read-only\n"); todo_wine { ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");