[PATCH 2 of 8] Properly handle the case that the file does not exist

Wald Commits scm-commit at wald.intevation.org
Mon Apr 28 11:22:45 CEST 2014


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1398676687 0
# Node ID e551de11d8b6a7cc20c3b4af68fa7b858c56a43c
# Parent  f925ddfe63013645f6be4187f6dc008d1ff83846
Properly handle the case that the file does not exist.

    TRUNCATE makes create file fail if the file does not exist
    but we need TRUNCATE in the case that the file already exists

diff -r f925ddfe6301 -r e551de11d8b6 cinst/nssstore_win.c
--- a/cinst/nssstore_win.c	Mon Apr 28 09:13:13 2014 +0000
+++ b/cinst/nssstore_win.c	Mon Apr 28 09:18:07 2014 +0000
@@ -480,9 +480,19 @@
                       0,
                       NULL);
 
+  if (hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND)
+    {
+      hFile = CreateFileW(path,
+                          GENERIC_WRITE,
+                          0, /* don't share */
+                          NULL, /* use the security attributes from the folder */
+                          CREATE_NEW,
+                          0,
+                          NULL);
+    }
   if (hFile == INVALID_HANDLE_VALUE)
     {
-      ERRORPRINTF ("Failed to create file\n");
+      PRINTLASTERROR ("Failed to create file\n");
       xfree(path);
       return NULL;
     }


More information about the Trustbridge-commits mailing list