/ Check-in [c90ed20d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the sqlite_temp_directory global variable which, if set, defines the directory in which temporary files are created. (CVS 1316)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | version_2
Files: files | file ages | folders
SHA1: c90ed20dc4f95eb06a5259578597593f5968bfb7
User & Date: drh 2004-05-07 00:57:06
Context
2004-05-07
01:46
Fix a memory leak in DETACH when using the codec. (CVS 1317) check-in: c4bd99b7 user: drh tags: version_2
00:57
Add the sqlite_temp_directory global variable which, if set, defines the directory in which temporary files are created. (CVS 1316) check-in: c90ed20d user: drh tags: version_2
2004-04-29
16:16
Fix a stack overflow problem with INSTEAD OF triggers. (CVS 1310) check-in: 5a33e0b0 user: drh tags: version_2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os.c.

   769    769       return SQLITE_CANTOPEN; 
   770    770     }
   771    771     TRACE3("OPENDIR %-3d %s\n", id->dirfd, zDirname);
   772    772   #endif
   773    773     return SQLITE_OK;
   774    774   }
   775    775   
          776  +/*
          777  +** If the following global variable points to a string which is the
          778  +** name of a directory, then that directory will be used to store
          779  +** temporary files.
          780  +*/
          781  +const char *sqlite_temp_directory = 0;
          782  +
   776    783   /*
   777    784   ** Create a temporary file name in zBuf.  zBuf must be big enough to
   778    785   ** hold at least SQLITE_TEMPNAME_SIZE characters.
   779    786   */
   780    787   int sqliteOsTempFileName(char *zBuf){
   781    788   #if OS_UNIX
   782    789     static const char *azDirs[] = {
          790  +     0,
   783    791        "/var/tmp",
   784    792        "/usr/tmp",
   785    793        "/tmp",
   786    794        ".",
   787    795     };
   788    796     static unsigned char zChars[] =
   789    797       "abcdefghijklmnopqrstuvwxyz"
   790    798       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   791    799       "0123456789";
   792    800     int i, j;
   793    801     struct stat buf;
   794    802     const char *zDir = ".";
          803  +  azDirs[0] = sqlite_temp_directory;
   795    804     for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
          805  +    if( azDirs[i]==0 ) continue;
   796    806       if( stat(azDirs[i], &buf) ) continue;
   797    807       if( !S_ISDIR(buf.st_mode) ) continue;
   798    808       if( access(azDirs[i], 07) ) continue;
   799    809       zDir = azDirs[i];
   800    810       break;
   801    811     }
   802    812     do{
................................................................................
   811    821   #endif
   812    822   #if OS_WIN
   813    823     static char zChars[] =
   814    824       "abcdefghijklmnopqrstuvwxyz"
   815    825       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   816    826       "0123456789";
   817    827     int i, j;
          828  +  char *zDir;
   818    829     char zTempPath[SQLITE_TEMPNAME_SIZE];
   819         -  GetTempPath(SQLITE_TEMPNAME_SIZE-30, zTempPath);
   820         -  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
   821         -  zTempPath[i] = 0;
          830  +  if( sqlite_temp_directory==0 ){
          831  +    GetTempPath(SQLITE_TEMPNAME_SIZE-30, zTempPath);
          832  +    for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
          833  +    zTempPath[i] = 0;
          834  +    zDir = zTempPath;
          835  +  }else{
          836  +    zDir = sqlite_temp_directory;
          837  +  }
   822    838     for(;;){
   823         -    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
          839  +    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zDir);
   824    840       j = strlen(zBuf);
   825    841       sqliteRandomness(15, &zBuf[j]);
   826    842       for(i=0; i<15; i++, j++){
   827    843         zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
   828    844       }
   829    845       zBuf[j] = 0;
   830    846       if( !sqliteOsFileExists(zBuf) ) break;
................................................................................
   832    848   #endif
   833    849   #if OS_MAC
   834    850     static char zChars[] =
   835    851       "abcdefghijklmnopqrstuvwxyz"
   836    852       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   837    853       "0123456789";
   838    854     int i, j;
          855  +  char *zDir;
   839    856     char zTempPath[SQLITE_TEMPNAME_SIZE];
   840    857     char zdirName[32];
   841    858     CInfoPBRec infoRec;
   842    859     Str31 dirName;
   843    860     memset(&infoRec, 0, sizeof(infoRec));
   844    861     memset(zTempPath, 0, SQLITE_TEMPNAME_SIZE);
   845         -  if( FindFolder(kOnSystemDisk, kTemporaryFolderType,  kCreateFolder,
          862  +  if( sqlite_temp_directory!=0 ){
          863  +    zDir = sqlite_temp_directory;
          864  +  }else if( FindFolder(kOnSystemDisk, kTemporaryFolderType,  kCreateFolder,
   846    865          &(infoRec.dirInfo.ioVRefNum), &(infoRec.dirInfo.ioDrParID)) == noErr ){
   847    866       infoRec.dirInfo.ioNamePtr = dirName;
   848    867       do{
   849    868         infoRec.dirInfo.ioFDirIndex = -1;
   850    869         infoRec.dirInfo.ioDrDirID = infoRec.dirInfo.ioDrParID;
   851    870         if( PBGetCatInfoSync(&infoRec) == noErr ){
   852    871           CopyPascalStringToC(dirName, zdirName);
................................................................................
   855    874           strcpy(zTempPath, zdirName);
   856    875           zTempPath[i] = ':';
   857    876         }else{
   858    877           *zTempPath = 0;
   859    878           break;
   860    879         }
   861    880       } while( infoRec.dirInfo.ioDrDirID != fsRtDirID );
          881  +    zDir = zTempPath;
   862    882     }
   863         -  if( *zTempPath == 0 )
          883  +  if( zDir[0]==0 ){
   864    884       getcwd(zTempPath, SQLITE_TEMPNAME_SIZE-24);
          885  +    zDir = zTempPath;
          886  +  }
   865    887     for(;;){
   866         -    sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath);
          888  +    sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zDir);
   867    889       j = strlen(zBuf);
   868    890       sqliteRandomness(15, &zBuf[j]);
   869    891       for(i=0; i<15; i++, j++){
   870    892         zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
   871    893       }
   872    894       zBuf[j] = 0;
   873    895       if( !sqliteOsFileExists(zBuf) ) break;

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.36 2004/02/22 17:49:34 drh Exp $
           16  +** $Id: test1.c,v 1.36.2.1 2004/05/07 00:57:06 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
   971    971   ** Register commands with the TCL interpreter.
   972    972   */
   973    973   int Sqlitetest1_Init(Tcl_Interp *interp){
   974    974     extern int sqlite_search_count;
   975    975     extern int sqlite_interrupt_count;
   976    976     extern int sqlite_open_file_count;
   977    977     extern int sqlite_current_time;
          978  +  extern int sqlite_temp_directory;
   978    979     static struct {
   979    980        char *zName;
   980    981        Tcl_CmdProc *xProc;
   981    982     } aCmd[] = {
   982    983        { "sqlite_mprintf_int",             (Tcl_CmdProc*)sqlite_mprintf_int    },
   983    984        { "sqlite_mprintf_str",             (Tcl_CmdProc*)sqlite_mprintf_str    },
   984    985        { "sqlite_mprintf_double",          (Tcl_CmdProc*)sqlite_mprintf_double },
................................................................................
  1016   1017         (char*)&sqlite_interrupt_count, TCL_LINK_INT);
  1017   1018     Tcl_LinkVar(interp, "sqlite_open_file_count", 
  1018   1019         (char*)&sqlite_open_file_count, TCL_LINK_INT);
  1019   1020     Tcl_LinkVar(interp, "sqlite_current_time", 
  1020   1021         (char*)&sqlite_current_time, TCL_LINK_INT);
  1021   1022     Tcl_LinkVar(interp, "sqlite_static_bind_value",
  1022   1023         (char*)&sqlite_static_bind_value, TCL_LINK_STRING);
         1024  +  Tcl_LinkVar(interp, "sqlite_temp_directory",
         1025  +      (char*)&sqlite_temp_directory, TCL_LINK_STRING);
  1023   1026     return TCL_OK;
  1024   1027   }