Bug 918612 - Stop masking the underlying Sqlite VFS version in the Telemetry VFS. r=bent

This commit is contained in:
Marco Bonardo 2013-10-23 14:58:06 +02:00
parent 30c9d18caa
commit 1e61ddb0c4

View File

@ -15,6 +15,12 @@
#include "mozilla/dom/quota/QuotaObject.h"
#include "mozilla/IOInterposer.h"
// The last VFS version for which this file has been updated.
#define LAST_KNOWN_VFS_VERSION 3
// The last io_methods version for which this file has been updated.
#define LAST_KNOWN_IOMETHODS_VERSION 3
/**
* This preference is a workaround to allow users/sysadmins to identify
* that the profile exists on an NFS share whose implementation
@ -400,10 +406,11 @@ xOpen(sqlite3_vfs* vfs, const char *zName, sqlite3_file* pFile,
sqlite3_io_methods *pNew = new sqlite3_io_methods;
const sqlite3_io_methods *pSub = p->pReal->pMethods;
memset(pNew, 0, sizeof(*pNew));
// If you update this version number, you must add appropriate IO methods
// for any methods added in the version change.
pNew->iVersion = 3;
MOZ_ASSERT(pNew->iVersion >= pSub->iVersion);
// If the io_methods version is higher than the last known one, you should
// update this VFS adding appropriate IO methods for any methods added in
// the version change.
pNew->iVersion = pSub->iVersion;
MOZ_ASSERT(pNew->iVersion <= LAST_KNOWN_IOMETHODS_VERSION);
pNew->xClose = xClose;
pNew->xRead = xRead;
pNew->xWrite = xWrite;
@ -416,19 +423,23 @@ xOpen(sqlite3_vfs* vfs, const char *zName, sqlite3_file* pFile,
pNew->xFileControl = xFileControl;
pNew->xSectorSize = xSectorSize;
pNew->xDeviceCharacteristics = xDeviceCharacteristics;
// Methods added in version 2.
pNew->xShmMap = pSub->xShmMap ? xShmMap : 0;
pNew->xShmLock = pSub->xShmLock ? xShmLock : 0;
pNew->xShmBarrier = pSub->xShmBarrier ? xShmBarrier : 0;
pNew->xShmUnmap = pSub->xShmUnmap ? xShmUnmap : 0;
// Methods added in version 3.
// SQLite 3.7.17 calls these methods without checking for nullptr first,
// so we always define them. Verify that we're not going to call
// nullptrs, though.
MOZ_ASSERT(pSub->xFetch);
pNew->xFetch = xFetch;
MOZ_ASSERT(pSub->xUnfetch);
pNew->xUnfetch = xUnfetch;
if (pNew->iVersion >= 2) {
// Methods added in version 2.
pNew->xShmMap = pSub->xShmMap ? xShmMap : 0;
pNew->xShmLock = pSub->xShmLock ? xShmLock : 0;
pNew->xShmBarrier = pSub->xShmBarrier ? xShmBarrier : 0;
pNew->xShmUnmap = pSub->xShmUnmap ? xShmUnmap : 0;
}
if (pNew->iVersion >= 3) {
// Methods added in version 3.
// SQLite 3.7.17 calls these methods without checking for nullptr first,
// so we always define them. Verify that we're not going to call
// nullptrs, though.
MOZ_ASSERT(pSub->xFetch);
pNew->xFetch = xFetch;
MOZ_ASSERT(pSub->xUnfetch);
pNew->xUnfetch = xUnfetch;
}
pFile->pMethods = pNew;
}
return rc;
@ -572,10 +583,11 @@ sqlite3_vfs* ConstructTelemetryVFS()
sqlite3_vfs *tvfs = new ::sqlite3_vfs;
memset(tvfs, 0, sizeof(::sqlite3_vfs));
// If you update this version number, you must add appropriate VFS methods
// for any methods added in the version change.
tvfs->iVersion = 3;
MOZ_ASSERT(vfs->iVersion == tvfs->iVersion);
// If the VFS version is higher than the last known one, you should update
// this VFS adding appropriate methods for any methods added in the version
// change.
tvfs->iVersion = vfs->iVersion;
MOZ_ASSERT(vfs->iVersion <= LAST_KNOWN_VFS_VERSION);
tvfs->szOsFile = sizeof(telemetry_file) - sizeof(sqlite3_file) + vfs->szOsFile;
tvfs->mxPathname = vfs->mxPathname;
tvfs->zName = "telemetry-vfs";
@ -592,13 +604,16 @@ sqlite3_vfs* ConstructTelemetryVFS()
tvfs->xSleep = xSleep;
tvfs->xCurrentTime = xCurrentTime;
tvfs->xGetLastError = xGetLastError;
// Methods added in version 2.
tvfs->xCurrentTimeInt64 = xCurrentTimeInt64;
// Methods added in version 3.
tvfs->xSetSystemCall = xSetSystemCall;
tvfs->xGetSystemCall = xGetSystemCall;
tvfs->xNextSystemCall = xNextSystemCall;
if (tvfs->iVersion >= 2) {
// Methods added in version 2.
tvfs->xCurrentTimeInt64 = xCurrentTimeInt64;
}
if (tvfs->iVersion >= 3) {
// Methods added in version 3.
tvfs->xSetSystemCall = xSetSystemCall;
tvfs->xGetSystemCall = xGetSystemCall;
tvfs->xNextSystemCall = xNextSystemCall;
}
return tvfs;
}