mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 17:33:08 +00:00
Identify a journal bundle by the presense of a tail field
This commit is contained in:
parent
e758e0130f
commit
62a4cd407d
@ -1323,8 +1323,18 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
|
||||
} else {
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Creating new manifest");
|
||||
if (journal){
|
||||
m->journalTail = 0;
|
||||
rhizome_manifest_set_ll(m,"tail",m->journalTail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (journal && m->journalTail==-1)
|
||||
return WHY("Existing manifest is not a journal");
|
||||
|
||||
if ((!journal) && m->journalTail>=0)
|
||||
return WHY("Existing manifest is a journal");
|
||||
|
||||
if (rhizome_fill_manifest(m, filepath, *authorSidHex?&authorSid:NULL, bskhex?&bsk:NULL)){
|
||||
rhizome_manifest_free(m);
|
||||
return -1;
|
||||
|
@ -135,7 +135,9 @@ typedef struct rhizome_manifest {
|
||||
/* When finalised, we keep the filehash and maximum priority due to any
|
||||
group membership handy */
|
||||
long long fileLength;
|
||||
long long journalTail;
|
||||
char fileHexHash[SHA512_DIGEST_STRING_LENGTH];
|
||||
|
||||
int fileHighestPriority;
|
||||
/* Absolute path of the file associated with the manifest */
|
||||
char *dataFileName;
|
||||
|
@ -109,6 +109,8 @@ int rhizome_read_manifest_file(rhizome_manifest *m, const char *filename, int bu
|
||||
|
||||
m->manifest_all_bytes=m->manifest_bytes;
|
||||
m->var_count=0;
|
||||
m->journalTail=-1;
|
||||
|
||||
/* Parse out variables, signature etc */
|
||||
int have_service = 0;
|
||||
int have_id = 0;
|
||||
@ -253,6 +255,16 @@ int rhizome_read_manifest_file(rhizome_manifest *m, const char *filename, int bu
|
||||
} else {
|
||||
m->payloadEncryption = atoi(value);
|
||||
}
|
||||
} else if (strcasecmp(var, "tail") == 0) {
|
||||
char *ep = value;
|
||||
long long tail = strtoll(value, &ep, 10);
|
||||
if (ep == value || *ep || tail < 0) {
|
||||
if (config.debug.rejecteddata)
|
||||
WARNF("Invalid tail: %s", value);
|
||||
m->errors++;
|
||||
} else {
|
||||
m->journalTail = tail;
|
||||
}
|
||||
} else {
|
||||
INFOF("Unsupported field: %s=%s", var, value);
|
||||
// This is not an error... older rhizome nodes must carry newer manifests.
|
||||
@ -513,6 +525,9 @@ rhizome_manifest *_rhizome_new_manifest(struct __sourceloc __whence)
|
||||
|
||||
if (config.debug.manifests) _log_manifest_trace(__whence, __FUNCTION__);
|
||||
|
||||
// Set global defaults for a manifest
|
||||
m->journalTail = -1;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -721,8 +721,7 @@ static int rhizome_pipe(struct rhizome_read *read, struct rhizome_write *write,
|
||||
int rhizome_write_open_journal(struct rhizome_write *write, rhizome_manifest *m, rhizome_bk_t *bsk, uint64_t advance_by, uint64_t new_size)
|
||||
{
|
||||
int ret = 0;
|
||||
if (advance_by!=0)
|
||||
return WHY("Advancing a journal is not yet supported");
|
||||
|
||||
if (advance_by > m->fileLength)
|
||||
return WHY("Cannot advance past the existing content");
|
||||
|
||||
@ -732,6 +731,11 @@ int rhizome_write_open_journal(struct rhizome_write *write, rhizome_manifest *m,
|
||||
DEBUGF("Before %lld, advance %lld, new %lld = %lld, %lld", old_length, advance_by, new_size, copy_length, m->fileLength);
|
||||
rhizome_manifest_set_ll(m, "filesize", m->fileLength);
|
||||
|
||||
if (advance_by>0){
|
||||
m->journalTail += advance_by;
|
||||
rhizome_manifest_set_ll(m,"tail",m->journalTail);
|
||||
}
|
||||
|
||||
m->version = m->fileLength;
|
||||
rhizome_manifest_set_ll(m,"version",m->version);
|
||||
|
||||
|
@ -666,11 +666,11 @@ test_EncryptedPayload() {
|
||||
|
||||
doc_JournalAdd="Create and append to a journal"
|
||||
setup_JournalAdd() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "Part One" > file1
|
||||
echo "Part Two" > file2
|
||||
cat file1 file2 > file
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "Part One" > file1
|
||||
echo "Part Two" > file2
|
||||
cat file1 file2 > file
|
||||
}
|
||||
test_JournalAdd() {
|
||||
executeOk_servald rhizome journal append $SIDB1 "" file1
|
||||
@ -684,6 +684,22 @@ test_JournalAdd() {
|
||||
assert diff file filex
|
||||
}
|
||||
|
||||
doc_AppendFile="Attempting to append to a non-journal fails"
|
||||
setup_AppendFile() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "Part One" > file1
|
||||
echo "Part Two" > file2
|
||||
executeOk_servald rhizome add file $SIDB1 file1
|
||||
tfw_cat --stdout --stderr
|
||||
assert_stdout_add_file file1
|
||||
extract_stdout_keyvalue BID 'manifestid' '[0-9A-F]\+'
|
||||
}
|
||||
test_AppendFile() {
|
||||
execute --exit-status=255 $servald rhizome journal append $SIDB1 $BID file2
|
||||
tfw_cat --stdout --stderr
|
||||
}
|
||||
|
||||
doc_MeshMSAddCreate="First add MeshMS creates manifest"
|
||||
setup_MeshMSAddCreate() {
|
||||
setup_servald
|
||||
|
Loading…
x
Reference in New Issue
Block a user