mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Add the "modeof=<filename>" URI parameter to os_unix.c - used to specify a file to copy permissions from when a new database is created. Also allow passing NULL as the second parameter to sqlite3rbu_vacuum().
FossilOrigin-Name: ed406d31ff54ee3de8db91690a966e5c561f8f94
This commit is contained in:
@@ -5529,6 +5529,27 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){
|
||||
return pUnused;
|
||||
}
|
||||
|
||||
/*
|
||||
** Find the mode, uid and gid of file zFile.
|
||||
*/
|
||||
static int getFileMode(
|
||||
const char *zFile, /* File name */
|
||||
mode_t *pMode, /* OUT: Permissions of zFile */
|
||||
uid_t *pUid, /* OUT: uid of zFile. */
|
||||
gid_t *pGid /* OUT: gid of zFile. */
|
||||
){
|
||||
struct stat sStat; /* Output of stat() on database file */
|
||||
int rc = SQLITE_OK;
|
||||
if( 0==osStat(zFile, &sStat) ){
|
||||
*pMode = sStat.st_mode & 0777;
|
||||
*pUid = sStat.st_uid;
|
||||
*pGid = sStat.st_gid;
|
||||
}else{
|
||||
rc = SQLITE_IOERR_FSTAT;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called by unixOpen() to determine the unix permissions
|
||||
** to create new files with. If no error occurs, then SQLITE_OK is returned
|
||||
@@ -5564,7 +5585,6 @@ static int findCreateFileMode(
|
||||
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
|
||||
char zDb[MAX_PATHNAME+1]; /* Database file path */
|
||||
int nDb; /* Number of valid bytes in zDb */
|
||||
struct stat sStat; /* Output of stat() on database file */
|
||||
|
||||
/* zPath is a path to a WAL or journal file. The following block derives
|
||||
** the path to the associated database file from zPath. This block handles
|
||||
@@ -5595,15 +5615,18 @@ static int findCreateFileMode(
|
||||
memcpy(zDb, zPath, nDb);
|
||||
zDb[nDb] = '\0';
|
||||
|
||||
if( 0==osStat(zDb, &sStat) ){
|
||||
*pMode = sStat.st_mode & 0777;
|
||||
*pUid = sStat.st_uid;
|
||||
*pGid = sStat.st_gid;
|
||||
}else{
|
||||
rc = SQLITE_IOERR_FSTAT;
|
||||
}
|
||||
rc = getFileMode(zDb, pMode, pUid, pGid);
|
||||
}else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
|
||||
*pMode = 0600;
|
||||
}else if( flags & SQLITE_OPEN_URI ){
|
||||
/* If this is a main database file and the file was opened using a URI
|
||||
** filename, check for the "modeof" parameter. If present, interpret
|
||||
** its value as a filename and try to copy the mode, uid and gid from
|
||||
** that file. */
|
||||
const char *z = sqlite3_uri_parameter(zPath, "modeof");
|
||||
if( z ){
|
||||
rc = getFileMode(z, pMode, pUid, pGid);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user