]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
VACUUM now uses a temporary file in the official TEMP folder instead of
authordrh <drh@noemail.net>
Tue, 10 Oct 2006 13:07:36 +0000 (13:07 +0000)
committerdrh <drh@noemail.net>
Tue, 10 Oct 2006 13:07:36 +0000 (13:07 +0000)
a file in the same directory as the original database. (CVS 3470)

FossilOrigin-Name: b743429dd54e2dcae213ec1993e9e916a9ba678d

manifest
manifest.uuid
src/vacuum.c

index bdd2cc70cedc7c0b5efbf91cf84eac0fec154052..e7ecd344c6599da5ce948717932ee7ed60bbf5b8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Version\s3.3.8\s(CVS\s3469)
-D 2006-10-09T00:38:42
+C VACUUM\snow\suses\sa\stemporary\sfile\sin\sthe\sofficial\sTEMP\sfolder\sinstead\sof\na\sfile\sin\sthe\ssame\sdirectory\sas\sthe\soriginal\sdatabase.\s(CVS\s3470)
+D 2006-10-10T13:07:36
 F Makefile.in 4379c909d46b38b8c5db3533084601621d4f14b2
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -112,7 +112,7 @@ F src/trigger.c 74ccec784683232f89f3b4db34a089d8cace2058
 F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129
 F src/utf.c f467b4892a75f60d36ee933be83f5d7562c5290e
 F src/util.c 91d4cb189476906639ae611927d939691d1365f6
-F src/vacuum.c f958275b353bcc54776601582ea35ed427125a9d
+F src/vacuum.c f6a7943f1f1002cb82ef2ea026cb1975a5b687cb
 F src/vdbe.c 84a9c0b0dd037c064ffed651977e20dd9d2bc1d1
 F src/vdbe.h 258b5d1c0aaa72192f09ff0568ce42b383f156fa
 F src/vdbeInt.h e3eaab262b67b84474625cfc38aec1125c32834b
@@ -402,7 +402,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 465ce5b2fe4462191dd02672838f3f903cd0f976
-R d4e345fce021c2c12806a776fa6efc70
+P 0658bb9e3f57e6aff4745590821a0590abc815f6
+R 63ed7158b28b067d212c207cfe64406b
 U drh
-Z f5c29a9882dd26aa4ecadab3f9bc4dad
+Z 3684897c97a0c2b8fc8841fe81c42ad8
index 575ec55015e67f5075341fcfcf11fd700432906c..3c38baab376402ebae56a6b521a9f3fcdd93a664 100644 (file)
@@ -1 +1 @@
-0658bb9e3f57e6aff4745590821a0590abc815f6
\ No newline at end of file
+b743429dd54e2dcae213ec1993e9e916a9ba678d
\ No newline at end of file
index 899559f504024517f288ce2899c67501c64c67aa..3f50b1ffb232e88ae69715e025c5ce8eb4977243 100644 (file)
 ** Most of the code in this file may be omitted by defining the
 ** SQLITE_OMIT_VACUUM macro.
 **
-** $Id: vacuum.c,v 1.63 2006/09/21 11:02:18 drh Exp $
+** $Id: vacuum.c,v 1.64 2006/10/10 13:07:36 drh Exp $
 */
 #include "sqliteInt.h"
 #include "vdbeInt.h"
 #include "os.h"
 
 #ifndef SQLITE_OMIT_VACUUM
-/*
-** Generate a random name of 20 character in length.
-*/
-static void randomName(unsigned char *zBuf){
-  static const unsigned char zChars[] =
-    "abcdefghijklmnopqrstuvwxyz"
-    "0123456789";
-  int i;
-  sqlite3Randomness(20, zBuf);
-  for(i=0; i<20; i++){
-    zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
-  }
-}
-
 /*
 ** Execute zSql on database db. Return an error code.
 */
@@ -92,14 +78,12 @@ void sqlite3Vacuum(Parse *pParse){
 */
 int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   int rc = SQLITE_OK;     /* Return code from service routines */
-  const char *zFilename;  /* full pathname of the database file */
-  int nFilename;          /* number of characters  in zFilename[] */
-  char *zTemp = 0;        /* a temporary file in same directory as zFilename */
   Btree *pMain;           /* The database being vacuumed */
-  Btree *pTemp;
-  char *zSql = 0;
-  int saved_flags;       /* Saved value of the db->flags */
-  Db *pDb = 0;           /* Database to detach at end of vacuum */
+  Btree *pTemp;           /* The temporary database we vacuum into */
+  char *zSql = 0;         /* SQL statements */
+  int saved_flags;        /* Saved value of the db->flags */
+  Db *pDb = 0;            /* Database to detach at end of vacuum */
+  char zTemp[SQLITE_TEMPNAME_SIZE+1];  /* Name of the TEMP file */
 
   /* Save the current value of the write-schema flag before setting it. */
   saved_flags = db->flags;
@@ -111,40 +95,8 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
     rc = SQLITE_ERROR;
     goto end_of_vacuum;
   }
-
-  /* Get the full pathname of the database file and create a
-  ** temporary filename in the same directory as the original file.
-  */
   pMain = db->aDb[0].pBt;
-  zFilename = sqlite3BtreeGetFilename(pMain);
-  assert( zFilename );
-  if( zFilename[0]=='\0' ){
-    /* The in-memory database. Do nothing. Return directly to avoid causing
-    ** an error trying to DETACH the vacuum_db (which never got attached)
-    ** in the exit-handler.
-    */
-    return SQLITE_OK;
-  }
-  nFilename = strlen(zFilename);
-  zTemp = sqliteMalloc( nFilename+100 );
-  if( zTemp==0 ){
-    rc = SQLITE_NOMEM;
-    goto end_of_vacuum;
-  }
-  strcpy(zTemp, zFilename);
-
-  /* The randomName() procedure in the following loop uses an excellent
-  ** source of randomness to generate a name from a space of 1.3e+31 
-  ** possibilities.  So unless the directory already contains on the order
-  ** of 1.3e+31 files, the probability that the following loop will
-  ** run more than once or twice is vanishingly small.  We are certain
-  ** enough that this loop will always terminate (and terminate quickly)
-  ** that we don't even bother to set a maximum loop count.
-  */
-  do {
-    zTemp[nFilename] = '-';
-    randomName((unsigned char*)&zTemp[nFilename+1]);
-  } while( sqlite3OsFileExists(zTemp) );
+  sqlite3OsTempFileName(zTemp);
 
   /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
   ** can be set to 'off' for this file, as it is not recovered if a crash
@@ -307,10 +259,6 @@ end_of_vacuum:
     pDb->pSchema = 0;
   }
 
-  if( zTemp ){
-    sqlite3OsDelete(zTemp);
-    sqliteFree(zTemp);
-  }
   sqliteFree( zSql );
   sqlite3ResetInternalSchema(db, 0);