aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-12-13 20:02:29 +0000
committerdrh <drh@noemail.net>2017-12-13 20:02:29 +0000
commita803a2cd9889cb3b4db1029110281370576bf354 (patch)
treef5830a317042fb58afca88421a1ae9da80dc7189 /src/os_unix.c
parent472e41ea16b2f338634ad31495d21dca62259eed (diff)
downloadsqlite-a803a2cd9889cb3b4db1029110281370576bf354.tar.gz
sqlite-a803a2cd9889cb3b4db1029110281370576bf354.zip
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
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 3c2f15ed0..e82cec233 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -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