# # # patch "database.cc" # from [6eb6abccd16cea2f3ec7517d4d0c1cb00e01fb69] # to [687fdf5f74a2e4f473f239f86fda86fd6b1e28a0] # # patch "work.cc" # from [8bb12080223afb25dc95e119bf6d29883c3e87c8] # to [cfe3da45cddb3838bf15bf380ad102df50ec461f] # # patch "work.hh" # from [5515f5af71490b7fd5ffc7e0d64f712df5b72a27] # to [3c13e0f3b441f11c46cb796c827668c4e39afddd] # ============================================================ --- database.cc 6eb6abccd16cea2f3ec7517d4d0c1cb00e01fb69 +++ database.cc 687fdf5f74a2e4f473f239f86fda86fd6b1e28a0 @@ -30,6 +30,7 @@ #include "database.hh" #include "hash_map.hh" #include "keys.hh" +#include "platform-wrapped.hh" #include "revision.hh" #include "safe_map.hh" #include "sanity.hh" @@ -3264,9 +3265,36 @@ database::check_db_exists() void database::check_db_exists() { - require_path_is_file(filename, - F("database %s does not exist") % filename, - F("%s is a directory, not a database") % filename); + switch (get_path_status(filename)) + { + case path::nonexistent: + N(false, F("database %s does not exist") % filename); + break; + case path::file: + return; + case path::directory: + { + system_path database_option; + branch_name branch_option; + rsa_keypair_id key_option; + system_path keydir_option; + if (workspace::get_ws_options_from_path( + filename, + database_option, + branch_option, + key_option, + keydir_option)) + { + N(database_option.empty(), + F("You gave a database option of: \n" + "%s\n" + "That is actually a workspace. Did you mean: \n" + "%s") % filename % database_option ); + } + N(false, F("%s is a directory, not a database") % filename); + } + break; + } } void ============================================================ --- work.cc 8bb12080223afb25dc95e119bf6d29883c3e87c8 +++ work.cc cfe3da45cddb3838bf15bf380ad102df50ec461f @@ -61,6 +61,13 @@ static void } static void +get_options_path(system_path & workspace, system_path & o_path) +{ + o_path = workspace / bookkeeping_root.as_internal() / options_file_name; + L(FL("options path is %s") % o_path); +} + +static void get_inodeprints_path(bookkeeping_path & ip_path) { ip_path = bookkeeping_root / inodeprints_file_name; @@ -228,16 +235,41 @@ workspace::get_ws_options(system_path & rsa_keypair_id & key_option, system_path & keydir_option) { - bookkeeping_path o_path; - get_options_path(o_path); + system_path empty_path; + get_ws_options_from_path(empty_path, database_option, + branch_option, key_option, keydir_option); +} + +bool +workspace::get_ws_options_from_path(system_path & workspace, + system_path & database_option, + branch_name & branch_option, + rsa_keypair_id & key_option, + system_path & keydir_option) +{ + any_path * o_path; + bookkeeping_path ws_o_path; + system_path sys_o_path; + + if (workspace.empty()) + { + get_options_path(ws_o_path); + o_path = & ws_o_path; + } + else + { + get_options_path(workspace, sys_o_path); + o_path = & sys_o_path; + } + try { - if (path_exists(o_path)) + if (path_exists(*o_path)) { data dat; - read_data(o_path, dat); + read_data(*o_path, dat); - basic_io::input_source src(dat(), o_path.as_external()); + basic_io::input_source src(dat(), o_path->as_external()); basic_io::tokenizer tok(src); basic_io::parser parser(tok); @@ -259,12 +291,17 @@ workspace::get_ws_options(system_path & W(F("unrecognized key '%s' in options file %s - ignored") % opt % o_path); } + return true; } + else + return false; } catch(exception & e) { - W(F("Failed to read options file %s: %s") % o_path % e.what()); + W(F("Failed to read options file %s: %s") % *o_path % e.what()); } + + return false; } void ============================================================ --- work.hh 5515f5af71490b7fd5ffc7e0d64f712df5b72a27 +++ work.hh 3c13e0f3b441f11c46cb796c827668c4e39afddd @@ -157,6 +157,11 @@ struct workspace // implied unless overridden on the command line. the set of valid keys // corresponds exactly to the argument list of these functions. + static bool get_ws_options_from_path(system_path & workspace, + system_path & database_option, + branch_name & branch_option, + rsa_keypair_id & key_option, + system_path & keydir_option); void get_ws_options(system_path & database_option, branch_name & branch_option, rsa_keypair_id & key_option,