SQLite

Check-in [1c0aa919ee]
Login

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

Overview
Comment:An improved way of generating the SQLITE_READONLY_DIRECTORY error. The error message submitted to sqlite3_log() is still correct this way.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15
User & Date: drh 2017-12-13 20:35:34.439
Context
2017-12-13
22:42
Add support for the 'lsm1.c' target in the MSVC makefile. (check-in: 6de21deac4 user: mistachkin tags: trunk)
20:35
An improved way of generating the SQLITE_READONLY_DIRECTORY error. The error message submitted to sqlite3_log() is still correct this way. (check-in: 1c0aa919ee user: drh tags: trunk)
20:02
New result code SQLITE_READONLY_DIRECTORY is returned when an attempt is made to write on a database file that is in a read-only directory and hence the journal file could not be created. This situation formerly returned SQLITE_CANTOPEN, which less helpful. (check-in: 3ec73c38f8 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_unix.c.
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923



5924
5925
5926
5927
5928
5929
5930
      assert( !p->pPreallocatedUnused );
      assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
      return rc;
    }
    fd = robust_open(zName, openFlags, openMode);
    OSTRACE(("OPENX   %-3d %s 0%o\n", fd, zName, openFlags));
    assert( !isExclusive || (openFlags & O_CREAT)!=0 );
    if( fd<0 && isNewJrnl && osAccess(zName, F_OK) ){
      /* Trying to create a journal file where we don't have write 
      ** permission on the directory */
      rc = unixLogError(SQLITE_READONLY_DIRECTORY, "open", zName);
      goto open_finished;
    }
    if( fd<0 && errno!=EISDIR && isReadWrite ){
      /* Failed to open the file for read/write access. Try read-only. */
      flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
      openFlags &= ~(O_RDWR|O_CREAT);
      flags |= SQLITE_OPEN_READONLY;
      openFlags |= O_RDONLY;
      isReadonly = 1;
      fd = robust_open(zName, openFlags, openMode);
    }
    if( fd<0 ){
      rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);



      goto open_finished;
    }

    /* If this process is running as root and if creating a new rollback
    ** journal or WAL file, set the ownership of the journal or WAL to be
    ** the same as the original database.
    */







<
<
<
<
<
<











>
>
>







5900
5901
5902
5903
5904
5905
5906






5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
      assert( !p->pPreallocatedUnused );
      assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
      return rc;
    }
    fd = robust_open(zName, openFlags, openMode);
    OSTRACE(("OPENX   %-3d %s 0%o\n", fd, zName, openFlags));
    assert( !isExclusive || (openFlags & O_CREAT)!=0 );






    if( fd<0 && errno!=EISDIR && isReadWrite ){
      /* Failed to open the file for read/write access. Try read-only. */
      flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
      openFlags &= ~(O_RDWR|O_CREAT);
      flags |= SQLITE_OPEN_READONLY;
      openFlags |= O_RDONLY;
      isReadonly = 1;
      fd = robust_open(zName, openFlags, openMode);
    }
    if( fd<0 ){
      rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
      /* If unable to create a journal, change the error code to
      ** indicate that the directory permissions are wrong. */
      if( isNewJrnl && osAccess(zName, F_OK) ) rc = SQLITE_READONLY_DIRECTORY;
      goto open_finished;
    }

    /* If this process is running as root and if creating a new rollback
    ** journal or WAL file, set the ownership of the journal or WAL to be
    ** the same as the original database.
    */