From eae16b82d31e3b999b80fed09dcbf6e79333c36e Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Wed, 1 May 2013 18:01:17 +0530 Subject: [PATCH] Fix issue #7. Ensure tempfile cleanup even with error abort. --- lzma/LzmaEnc.c | 56 +++++++++++++++++++++----------------------- rabin/global/index.c | 12 +++++----- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/lzma/LzmaEnc.c b/lzma/LzmaEnc.c index b7ddd6a..ac263de 100644 --- a/lzma/LzmaEnc.c +++ b/lzma/LzmaEnc.c @@ -1,28 +1,28 @@ -/* - * This file is a part of Pcompress, a chunked parallel multi- - * algorithm lossless compression and decompression program. - * - * Copyright (C) 2012-2013 Moinak Ghosh. All rights reserved. - * Use is subject to license terms. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. - * If not, see . - * - * moinakg@belenix.org, http://moinakg.wordpress.com/ - * - */ - +/* + * This file is a part of Pcompress, a chunked parallel multi- + * algorithm lossless compression and decompression program. + * + * Copyright (C) 2012-2013 Moinak Ghosh. All rights reserved. + * Use is subject to license terms. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program. + * If not, see . + * + * moinakg@belenix.org, http://moinakg.wordpress.com/ + * + */ + /* LzmaEnc.c -- LZMA Encoder 2010-04-16 : Igor Pavlov : Public domain */ @@ -83,8 +83,7 @@ static int ttt = 0; "movntiq %[val], (%[ptr1]);"\ "movntiq %[val], 0x8(%[ptr1]);"\ : \ - : [ptr1] "q" (mem), [val] "q" (val) \ - :) + : [ptr1] "q" (mem), [val] "q" (val) ) #define MOV_DBL_QUAD_UNALIGNED(mem, val) \ *((UInt64 *)(mem)) = val; *((UInt64 *)((Byte *)mem + 8)) = val @@ -94,8 +93,7 @@ static int ttt = 0; "movntiq %[val], 0x10(%[ptr1]);"\ "movntiq %[val], 0x18(%[ptr1]);"\ : \ - : [ptr1] "q" (mem), [val] "q" (val) \ - :) + : [ptr1] "q" (mem), [val] "q" (val) ) #define MOV_QUAD_QUAD_UNALIGNED(mem, val) \ *((UInt64 *)(mem)) = val; *((UInt64 *)((Byte *)mem + 8)) = val; \ *((UInt64 *)((Byte *)mem + 16)) = val; *((UInt64 *)((Byte *)mem + 24)) = val diff --git a/rabin/global/index.c b/rabin/global/index.c index 6793d82..4254c6a 100644 --- a/rabin/global/index.c +++ b/rabin/global/index.c @@ -291,6 +291,12 @@ init_global_db_s(char *path, char *tmppath, uint32_t chunksize, uint64_t user_ch cfg->seg_fd_r[i].mapping = NULL; } + /* + * Remove tempfile entry from the filesystem metadata so that file gets + * automatically removed once process exits. + */ + unlink(cfg->rootdir); + if (errored) { cleanup_indx(indx); if (cfg->seg_fd_r) @@ -298,12 +304,6 @@ init_global_db_s(char *path, char *tmppath, uint32_t chunksize, uint64_t user_ch free(cfg); return (NULL); } - - /* - * Remove tempfile entry from the filesystem metadata so that file gets - * automatically removed once process exits. - */ - unlink(cfg->rootdir); } cfg->segcache_pos = 0; cfg->dbdata = indx;