mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Auto move rhizome store when config is first set
This commit is contained in:
parent
5e0e59e8b8
commit
39f582ccab
@ -244,22 +244,6 @@ int rhizome_opendb()
|
||||
if (emkdirs_info(rhizome_database.folder, 0700)==-1)
|
||||
RETURN (-1);
|
||||
char dbpath[1024];
|
||||
if (!FORMF_RHIZOME_STORE_PATH(dbpath, RHIZOME_BLOB_SUBDIR))
|
||||
RETURN(-1);
|
||||
if (emkdirs_info(dbpath, 0700) == -1)
|
||||
RETURN(-1);
|
||||
if (!FORMF_RHIZOME_STORE_PATH(dbpath, RHIZOME_HASH_SUBDIR))
|
||||
RETURN(-1);
|
||||
if (emkdirs_info(dbpath, 0700) == -1)
|
||||
RETURN(-1);
|
||||
if (!sqlite3_temp_directory) {
|
||||
if (!FORMF_RHIZOME_STORE_PATH(dbpath, "sqlite3tmp"))
|
||||
RETURN(-1);
|
||||
if (emkdirs_info(dbpath, 0700) == -1)
|
||||
RETURN(-1);
|
||||
sqlite3_temp_directory = sqlite3_mprintf("%s", dbpath);
|
||||
}
|
||||
sqlite3_config(SQLITE_CONFIG_LOG,sqlite_log,NULL);
|
||||
|
||||
if (!FORMF_RHIZOME_STORE_PATH(dbpath, "rhizome.db"))
|
||||
RETURN(-1);
|
||||
@ -268,6 +252,47 @@ int rhizome_opendb()
|
||||
if (get_file_meta(dbpath, &meta) == -1)
|
||||
RETURN(-1);
|
||||
|
||||
if (meta.mtime.tv_sec == -1 && config.rhizome.datastore_path[0]){
|
||||
// Move the database after datastore path is set for the first time
|
||||
// This is mostly here to transparently fix a bug where we were ignoring the config value
|
||||
char src[1024];
|
||||
char dest[1024];
|
||||
if (formf_rhizome_store_path(src, sizeof src, "rhizome.db")
|
||||
&& strcmp(dbpath, src)!=0
|
||||
&& get_file_meta(src, &meta)==0
|
||||
&& meta.mtime.tv_sec != -1){
|
||||
|
||||
INFOF("Moving rhizome store from %s to %s", src, dbpath);
|
||||
if (rename(src, dbpath))
|
||||
WHYF_perror("rename(%s, %s)", src, dbpath);
|
||||
|
||||
if (formf_rhizome_store_path(src, sizeof src, RHIZOME_BLOB_SUBDIR)
|
||||
&& FORMF_RHIZOME_STORE_PATH(dest, RHIZOME_BLOB_SUBDIR)
|
||||
&& rename(src, dest)
|
||||
&& errno!=ENOENT){
|
||||
WHYF_perror("rename(%s, %s)", src, dest);
|
||||
}
|
||||
|
||||
if (formf_rhizome_store_path(src, sizeof src, RHIZOME_HASH_SUBDIR)
|
||||
&& FORMF_RHIZOME_STORE_PATH(dest, RHIZOME_HASH_SUBDIR)
|
||||
&& rename(src, dest)
|
||||
&& errno!=ENOENT){
|
||||
WHYF_perror("rename(%s, %s)", src, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sqlite3_temp_directory){
|
||||
char tmp[1024];
|
||||
if (!FORMF_RHIZOME_STORE_PATH(tmp, "sqlite3tmp"))
|
||||
RETURN(-1);
|
||||
if (emkdirs_info(tmp, 0700) == -1)
|
||||
RETURN(-1);
|
||||
sqlite3_temp_directory = sqlite3_mprintf("%s", tmp);
|
||||
}
|
||||
|
||||
sqlite3_config(SQLITE_CONFIG_LOG,sqlite_log,NULL);
|
||||
|
||||
if (sqlite3_open(dbpath,&rhizome_database.db)){
|
||||
RETURN(WHYF("SQLite could not open database %s: %s", dbpath, sqlite3_errmsg(rhizome_database.db)));
|
||||
}
|
||||
@ -438,6 +463,9 @@ int rhizome_close_db()
|
||||
RETURN(WHYF("Failed to close sqlite database, %s",sqlite3_errmsg(rhizome_database.db)));
|
||||
}
|
||||
rhizome_database.db=NULL;
|
||||
if (sqlite3_temp_directory)
|
||||
sqlite3_free(sqlite3_temp_directory);
|
||||
sqlite3_temp_directory=NULL;
|
||||
RETURN(0);
|
||||
OUT();
|
||||
}
|
||||
|
@ -431,6 +431,8 @@ static int write_get_lock(struct rhizome_write *write_state)
|
||||
if (!FORMF_RHIZOME_STORE_PATH(blob_path, "%s/%"PRIu64, RHIZOME_BLOB_SUBDIR, write_state->temp_id))
|
||||
return -1;
|
||||
DEBUGF(rhizome_store, "Attempting to put blob for id='%"PRIu64"' in %s", write_state->temp_id, blob_path);
|
||||
if (emkdirsn(blob_path, strrchr(blob_path,'/') - blob_path, 0700) == -1)
|
||||
return -1;
|
||||
if ((write_state->blob_fd = open(blob_path, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
|
||||
WHYF("Failed to create payload file, id='%"PRIu64"'", write_state->temp_id);
|
||||
return -1;
|
||||
|
@ -69,15 +69,14 @@ setup_DatabaseFolder() {
|
||||
set debug.rhizome_manifest on \
|
||||
set debug.verbose on \
|
||||
set log.console.level debug \
|
||||
set rhizome.datastore_path "$instance_dir/moved_rhizome"
|
||||
set rhizome.datastore_path "$instance_dir/rhizome"
|
||||
}
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
executeOk_servald rhizome list
|
||||
}
|
||||
test_DatabaseFolder() {
|
||||
executeOk find "$instance_dir"
|
||||
assert [ -e "$instance_dir/moved_rhizome/rhizome.db" ]
|
||||
executeOk_servald rhizome list
|
||||
assert [ -e "$instance_dir/rhizome/rhizome.db" ]
|
||||
}
|
||||
|
||||
doc_InitialEmptyList="Initial list is empty"
|
||||
@ -304,6 +303,23 @@ test_AddThenList() {
|
||||
assert_rhizome_list --fromhere=1 --author="$SIDA" file1 file2
|
||||
}
|
||||
|
||||
doc_MoveDatabaseFolder="Database is moved after config change"
|
||||
setup_MoveDatabaseFolder() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
executeOk_servald config set rhizome.max_blob_size 0
|
||||
echo "A test file" >file1
|
||||
executeOk_servald rhizome add file "$SIDA" file1 file1.manifest
|
||||
}
|
||||
test_MoveDatabaseFolder() {
|
||||
executeOk_servald config \
|
||||
set rhizome.datastore_path "$instance_dir/moved_rhizome"
|
||||
executeOk_servald rhizome list
|
||||
assert_rhizome_list --fromhere=1 --author="$SIDA" file1
|
||||
assert [ ! -e "$instance_dir/rhizome.db" ]
|
||||
assert [ -e "$instance_dir/moved_rhizome/rhizome.db" ]
|
||||
}
|
||||
|
||||
doc_CleanVerify="Verify all bundles"
|
||||
setup_CleanVerify() {
|
||||
setup_servald
|
||||
|
Loading…
Reference in New Issue
Block a user