Changeset: 57f925797ea1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=57f925797ea1
Modified Files:
        gdk/gdk_posix.c
        gdk/gdk_storage.c
Branch: Jun2016
Log Message:

Truncate file back to original size after failed extend.
This should solve bug 4013.


diffs (36 lines):

diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -623,6 +623,13 @@ MT_mremap(const char *path, int mode, vo
 #endif
 #endif
                                                ) {
+                                               int err = errno;
+                                               /* extending failed:
+                                                * free any disk space
+                                                * allocated in the
+                                                * process */
+                                               (void) ftruncate(fd, (off_t) 
old_size);
+                                               errno = err; /* restore for 
error message */
                                                GDKsyserror("MT_mremap: growing 
file failed\n");
                                                close(fd);
                                                fprintf(stderr,
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -349,8 +349,14 @@ GDKextendf(int fd, size_t size, const ch
                 * is not supported on the file system, or if neither
                 * function exists */
                rt = ftruncate(fd, (off_t) size);
-               if (rt != 0)
+               if (rt != 0) {
+                       /* extending failed, try to reduce file size
+                        * back to original */
+                       int err = errno;
+                       (void) ftruncate(fd, stb.st_size);
+                       errno = err; /* restore for error message */
                        GDKsyserror("GDKextendf: could not extend file\n");
+               }
        }
        IODEBUG fprintf(stderr, "#GDKextend %s " SZFMT " -> " SZFMT " %dms%s\n",
                        fn, (size_t) stb.st_size, size,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to