1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

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.

FossilOrigin-Name: 3ec73c38f878d73d278fce99ba10c708dcc475835774f1e17769ff7315be6d7c
This commit is contained in:
drh
2017-12-13 20:02:29 +00:00
parent 472e41ea16
commit a803a2cd98
4 changed files with 18 additions and 11 deletions

View File

@@ -5799,7 +5799,7 @@ static int unixOpen(
** a file-descriptor on the directory too. The first time unixSync()
** is called the directory file descriptor will be fsync()ed and close()d.
*/
int syncDir = (isCreate && (
int isNewJrnl = (isCreate && (
eType==SQLITE_OPEN_MASTER_JOURNAL
|| eType==SQLITE_OPEN_MAIN_JOURNAL
|| eType==SQLITE_OPEN_WAL
@@ -5869,7 +5869,7 @@ static int unixOpen(
}else if( !zName ){
/* If zName is NULL, the upper layer is requesting a temp file. */
assert(isDelete && !syncDir);
assert(isDelete && !isNewJrnl);
rc = unixGetTempname(pVfs->mxPathname, zTmpname);
if( rc!=SQLITE_OK ){
return rc;
@@ -5904,6 +5904,12 @@ static int unixOpen(
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);
@@ -5974,7 +5980,7 @@ static int unixOpen(
if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
noLock = eType!=SQLITE_OPEN_MAIN_DB;
if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK;
if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
if( isNewJrnl ) ctrlFlags |= UNIXFILE_DIRSYNC;
if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
#if SQLITE_ENABLE_LOCKING_STYLE