mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-08 03:24:13 +00:00
Document recommended sql queries
This commit is contained in:
parent
884e427fbb
commit
0e75cbdcad
@ -451,6 +451,18 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
{
|
||||
if (!m->finalised) return WHY("Manifest was not finalised");
|
||||
|
||||
if (m->haveSecret) {
|
||||
/* We used to store the secret in the database, but we don't anymore, as we use
|
||||
the BK field in the manifest. So nothing to do here. */
|
||||
} else {
|
||||
/* We don't have the secret for this manifest, so only allow updates if
|
||||
the self-signature is valid */
|
||||
if (!m->selfSigned) {
|
||||
WHY("*** Insert into manifests failed (-2).");
|
||||
return WHY("Manifest is not signed, and I don't have the key. Manifest might be forged or corrupt.");
|
||||
}
|
||||
}
|
||||
|
||||
char manifestid[RHIZOME_MANIFEST_ID_STRLEN + 1];
|
||||
rhizome_manifest_get(m, "id", manifestid, sizeof manifestid);
|
||||
str_toupper_inplace(manifestid);
|
||||
@ -459,6 +471,47 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
strncpy(filehash, m->fileHexHash, sizeof filehash);
|
||||
str_toupper_inplace(filehash);
|
||||
|
||||
|
||||
/* process should be;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
try{
|
||||
// insert new file contents, if not already there
|
||||
|
||||
// dont risk losing the old manifest if something fails
|
||||
UPDATE MANIFESTS
|
||||
SET manifest = ?,
|
||||
version = ?,
|
||||
insserttime = ?,
|
||||
bar = ?
|
||||
WHERE id = ?;
|
||||
|
||||
if (no rows updated){
|
||||
INSERT INTO MANIFESTS (id,manifest,version,inserttime,bar)
|
||||
VALUES (?,?,?,?,?);
|
||||
}
|
||||
|
||||
// remove reference to any old file versions
|
||||
DELETE FROM FILEMANIFESTS
|
||||
WHERE manifestid=?
|
||||
AND fileid != ?;
|
||||
|
||||
// remove unreferenced files
|
||||
DELETE FROM FILES f
|
||||
AND NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM FILEMANIFESTS fm
|
||||
AND fm.fileid = f.id
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
}catch (){
|
||||
// if one step fails, all fail.
|
||||
ROLLBACK;
|
||||
}
|
||||
*/
|
||||
|
||||
/* remove any old version of the manifest */
|
||||
if (sqlite_exec_int64("SELECT COUNT(*) FROM MANIFESTS WHERE id='%s';",manifestid)>0)
|
||||
{
|
||||
@ -485,18 +538,6 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
"INSERT INTO MANIFESTS(id,manifest,version,inserttime,bar) VALUES('%s',?,%lld,%lld,?);",
|
||||
manifestid, m->version, gettime_ms());
|
||||
|
||||
if (m->haveSecret) {
|
||||
/* We used to store the secret in the database, but we don't anymore, as we use
|
||||
the BK field in the manifest. So nothing to do here. */
|
||||
} else {
|
||||
/* We don't have the secret for this manifest, so only allow updates if
|
||||
the self-signature is valid */
|
||||
if (!m->selfSigned) {
|
||||
WHY("*** Insert into manifests failed (-2).");
|
||||
return WHY("Manifest is not signed, and I don't have the key. Manifest might be forged or corrupt.");
|
||||
}
|
||||
}
|
||||
|
||||
const char *cmdtail;
|
||||
sqlite3_stmt *statement;
|
||||
if (sqlite3_prepare_v2(rhizome_db,sqlcmd,strlen(sqlcmd)+1,&statement,&cmdtail) != SQLITE_OK) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user