changeset 180:d434e771c776 no-big-mmap

checks for enough free data space don't use dataBuf any more
author mas01cr
date Thu, 15 Nov 2007 16:38:53 +0000
parents 71c24d0df2c4
children c22d53219112
files audioDB.cpp audioDB.h
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.cpp	Thu Nov 15 16:22:59 2007 +0000
+++ b/audioDB.cpp	Thu Nov 15 16:38:53 2007 +0000
@@ -542,6 +542,10 @@
   initInputFile(inFile);
 }
 
+bool audioDB::enough_data_space_free(off_t size) {
+  return(dbH->timesTableOffset > dbH->dataOffset + dbH->length + size);
+}
+
 void audioDB::insert(const char* dbName, const char* inFile) {
   forWrite = true;
   initTables(dbName, inFile);
@@ -549,10 +553,10 @@
   if(!usingTimes && (dbH->flags & O2_FLAG_TIMES))
     error("Must use timestamps with timestamped database","use --times");
 
-  // Check that there is room for at least 1 more file
-  if((char*)timesTable<((char*)dataBuf+dbH->length+statbuf.st_size-sizeof(int)))
+  if(!enough_data_space_free(statbuf.st_size - sizeof(int))) {
     error("Insert failed: no more room in database", inFile);
-  
+  }
+
   if(!key)
     key=inFile;
   // Linear scan of filenames check for pre-existing feature
@@ -716,9 +720,9 @@
 
     initInputFile(thisFile);
 
-    // Check that there is room for at least 1 more file
-    if((char*)timesTable<((char*)dataBuf+(dbH->length+statbuf.st_size-sizeof(int))))
+    if(!enough_data_space_free(statbuf.st_size - sizeof(int))) {
       error("batchinsert failed: no more room in database", thisFile);
+    }
     
     // Linear scan of filenames check for pre-existing feature
     unsigned alreadyInserted=0;
--- a/audioDB.h	Thu Nov 15 16:22:59 2007 +0000
+++ b/audioDB.h	Thu Nov 15 16:38:53 2007 +0000
@@ -199,6 +199,7 @@
   void release_lock(int fd);
   void create(const char* dbName);
   void drop();
+  bool enough_data_space_free(off_t size);
   void insert(const char* dbName, const char* inFile);
   void batchinsert(const char* dbName, const char* inFile);
   void query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse=0);