changeset 502:e551de11d8b6

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
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 28 Apr 2014 09:18:07 +0000
parents f925ddfe6301
children 7f2cb85288d0
files cinst/nssstore_win.c
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }

http://wald.intevation.org/projects/trustbridge/