[Groonga-commit] groonga/groonga at cea406e [master] io windows: delete unexpectedly created file by CreateFile() error

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Aug 8 18:25:13 JST 2018


Kouhei Sutou	2018-08-08 18:25:13 +0900 (Wed, 08 Aug 2018)

  New Revision: cea406e0d00e4fb996d38fd70ac78ad5c752187a
  https://github.com/groonga/groonga/commit/cea406e0d00e4fb996d38fd70ac78ad5c752187a

  Message:
    io windows: delete unexpectedly created file by CreateFile() error

  Modified files:
    lib/io.c

  Modified: lib/io.c (+20 -0)
===================================================================
--- lib/io.c    2018-08-08 18:10:23 +0900 (6e0d0604d)
+++ lib/io.c    2018-08-08 18:25:13 +0900 (6be59c6a6)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -1741,8 +1742,17 @@ grn_fileinfo_open_common(grn_ctx *ctx, fileinfo *fi, const char *path, int flags
 {
   /* may be wrong if flags is just only O_RDWR */
   if ((flags & O_CREAT)) {
+    grn_bool exist = GRN_FALSE;
     DWORD dwCreationDisposition;
     const char *flags_description;
+
+    {
+      struct stat stat_buffer;
+      if (stat(path, &stat_buffer) == 0) {
+        exist = GRN_TRUE;
+      }
+    }
+
     if (flags & O_EXCL) {
       dwCreationDisposition = CREATE_NEW;
       flags_description = "O_RDWR|O_CREAT|O_EXCL";
@@ -1757,6 +1767,16 @@ grn_fileinfo_open_common(grn_ctx *ctx, fileinfo *fi, const char *path, int flags
     if (fi->fh == INVALID_HANDLE_VALUE) {
       SERR("CreateFile(<%s>, <%s>) failed",
            path, flags_description);
+      if (!exist) {
+        struct stat stat_buffer;
+        if (stat(path, &stat_buffer) == 0) {
+          GRN_LOG(ctx, GRN_LOG_INFO,
+                  "[io][open] "
+                  "delete a newly created file because of open error: <%s>",
+                  path);
+          DeleteFile(path);
+        }
+      }
       goto exit;
     }
 
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180808/91039513/attachment-0001.htm 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index