diff options
Diffstat (limited to 'src/context.c')
-rw-r--r-- | src/context.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/context.c b/src/context.c index f64040a..7052bad 100644 --- a/src/context.c +++ b/src/context.c @@ -29,6 +29,7 @@ #include "context.h" #include "package.h" +#include "util.h" int db_context_free(struct syrep_db_context* c) { if (c) { @@ -87,7 +88,7 @@ static DB* open_db(const char*path, int dup) { return db; } -struct syrep_db_context* db_context_open(const char *filename) { +struct syrep_db_context* db_context_open(const char *filename, int force) { struct syrep_db_context *c = NULL; const char* path; FILE *f; @@ -97,7 +98,7 @@ struct syrep_db_context* db_context_open(const char *filename) { memset(c, 0, sizeof(struct syrep_db_context)); - if (!(c->package = package_open(filename))) + if (!(c->package = package_open(filename, force))) goto fail; path = package_get_item(c->package, "timestamp", 1); @@ -217,3 +218,24 @@ int db_context_save(struct syrep_db_context *c, const char *filename) { return package_save(c->package, filename); } + +int db_context_origin_warn(struct syrep_db_context *c) { + char hn[256]; + + assert(c); + + if (gethostname(hn, sizeof(hn)) < 0) + return -1; + + if (strcmp(hn, c->origin)) { + int q; + + if (!(q = question("WARNING: Snapshot is not from local host! Continue?", "ny"))) + return -1; + + if (q != 'y') + return 1; + } + + return 0; +} |