Kentaro Hayashi
null+****@clear*****
Fri Sep 15 12:47:19 JST 2017
Kentaro Hayashi 2017-08-16 18:08:59 +0900 (Wed, 16 Aug 2017) New Revision: 1afab01ac0b5ac59c593f003a12bbe3120da8f72 https://github.com/groonga/groonga/commit/1afab01ac0b5ac59c593f003a12bbe3120da8f72 Merged 1a1a6a6: Merge pull request #759 from kenhys/suppress-0byte-file Message: io: don't keep created empty file on error In the previous versions, there is a case that empty file keeps remain on error. Here is the senario to reproduce: 1. creating new file by grn_fileinfo_open succeeds 2. mapping file by DO_MAP() is failed In such a case, it causes an another error such as "already file exists" because of the file which isn't under control. so these file should be removed during cleanup process. Modified files: lib/io.c Modified: lib/io.c (+11 -0) =================================================================== --- lib/io.c 2017-09-12 17:53:12 +0900 (48a9d7659) +++ lib/io.c 2017-08-16 18:08:59 +0900 (4dc0e0172) @@ -29,6 +29,7 @@ #include "grn_plugin.h" #include "grn_hash.h" #include "grn_ctx_impl.h" +#include "grn_util.h" #ifdef WIN32 # include <io.h> @@ -1223,9 +1224,19 @@ grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *info) fileinfo *fi = &io->fis[fno]; if (!grn_fileinfo_opened(fi)) { char path[PATH_MAX]; + grn_bool path_exist = GRN_TRUE; gen_pathname(io->path, path, fno); + path_exist = grn_path_exist(path); if (!grn_fileinfo_open(ctx, fi, path, O_RDWR|O_CREAT)) { DO_MAP(io, &info->fmo, fi, pos, segment_size, segno, info->map); + if (!info->map && !path_exist) { + if (grn_unlink(path) == 0) { + GRN_LOG(ctx, GRN_LOG_INFO, + "[io][map][error] removed empty file: <%s>", path); + } else { + ERRNO_ERR("[io][map][error] failed to remove empty file: <%s>", path); + } + } } } else { DO_MAP(io, &info->fmo, fi, pos, segment_size, segno, info->map); -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170915/1c62eb5d/attachment.htm