errno to catch the last segment
authorCédric Villemain <cedric.villemain.debian@gmail.com>
Sun, 7 Feb 2010 03:05:58 +0000 (04:05 +0100)
committerCédric Villemain <cedric.villemain.debian@gmail.com>
Sun, 7 Feb 2010 03:05:58 +0000 (04:05 +0100)
ChangeLog
pgfincore.c

index e09c3c7ed91f64b50a2b458ba5a7403f6ed0ffe8..b5d97278727b6cc3f5e6bd7f0987f9008a92d624 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+02/05/2010 Cédric Villemain <cedric@villemain.org>
+
+  * 0.4.1 - use AllocateFile instead of fopen
+                 - call PG_GETARG* earlier
+                 - remove useless global counter
+                 - add error handler in pgfadv_snapshot()
+                 - errno to catch the last segment
+
 01/05/2010 Cédric Villemain <cedric@villemain.org>
 
   * 0.4.0 - fix test is not temp table
index e0fd2639806f1041ad4ce4a6b79c64e6ee959839..79d849b9fae382307bbf8ed90e03e5769c26da6b 100644 (file)
@@ -96,7 +96,6 @@ pgfincore(PG_FUNCTION_ARGS)
   pgfincore_fctx  *fctx;
   Datum                  result;
   char                   pathname[MAXPGPATH];
-  bool                           isnull;
 
   /* stuff done only on the first call of the function */
   if (SRF_IS_FIRSTCALL())
@@ -190,8 +189,7 @@ pgfincore(PG_FUNCTION_ARGS)
   * When we have work with all segment of the current relation, test success
   * We exit from the SRF
   */
-  if (DatumGetInt64(GetAttributeByName((HeapTupleHeader)result, "block_disk", &isnull)) == 0
-       || isnull )
+  if (errno == ENOENT )
   {
        relation_close(fctx->rel, AccessShareLock);
        pfree(fctx);
@@ -359,7 +357,6 @@ pgmincore_file(char *filename, int action, FunctionCallInfo fcinfo)
   free(vec);
   munmap(pa, st.st_size);
   close(fd);
-
   return HeapTupleGetDatum(tuple); /* return filename, block_disk, block_mem, group_mem   */
 
 error:
@@ -370,6 +367,7 @@ error:
   values[4] = Int64GetDatum(false);
   memset(nulls, 0, sizeof(nulls));
   tuple = heap_form_tuple(tupdesc, values, nulls);
+  errno = ENOENT;
   return (HeapTupleGetDatum(tuple));
 }
 
@@ -472,6 +470,7 @@ error:
   values[3] = Int64GetDatum(false);
   memset(nulls, 0, sizeof(nulls));
   tuple = heap_form_tuple(tupdesc, values, nulls);
+  errno = ENOENT;
   return (HeapTupleGetDatum(tuple));
 }
 
@@ -507,7 +506,7 @@ pgfadv_snapshot(char *filename, int fd, int action)
          if (file == NULL)
          {
                  if (errno == ENOENT)
-                         return;                               /* ignore not-found error */
+                         return block_mem;                             /* ignore not-found error */
                  goto error;
          }
 
@@ -553,4 +552,5 @@ error:
                FreeFile(file);
        /* If possible, throw away the bogus file; ignore any error */
        unlink(path);
+       return block_mem;
 }