# # # patch "cmd_netsync.cc" # from [6ef34c4984518f3151c25cff2dcac621a2f539ec] # to [1fb1c4de8ea4eab675c08675fa1dd3bae086ce4e] # # patch "database.cc" # from [7770e394d00b075de203a5c054350b1c44c98349] # to [99171b1f3f3aeceb00da62cb3d74667e9be7e8bf] # # patch "database.hh" # from [6c591fe758a0dcb3706813f9fa100fae9a37c6f6] # to [ac3f29cd6d2f86ef60802f9c0674df6d2b578a7d] # # patch "tests/clone_warning_with_multiple_heads/__driver__.lua" # from [9d313a067d5944fdebbaf9595c791e5a4a1a16c4] # to [a64e816452073997cce0f45ec970e5b42a076067] # ============================================================ --- cmd_netsync.cc 6ef34c4984518f3151c25cff2dcac621a2f539ec +++ cmd_netsync.cc 1fb1c4de8ea4eab675c08675fa1dd3bae086ce4e @@ -170,11 +170,16 @@ public: class dir_cleanup_helper { public: - dir_cleanup_helper(system_path const & new_dir) : commited(false), dir(new_dir) {} + dir_cleanup_helper(system_path const & new_dir, app_state *app_st, bool i_db) : + commited(false), internal_db(i_db), dir(new_dir), app(app_st) {} ~dir_cleanup_helper() { if (!commited && directory_exists(dir)) - delete_dir_recursive(dir); + { + if (internal_db && app) + app->db.close(); + delete_dir_recursive(dir); + } } void commit(void) { @@ -182,7 +187,9 @@ private: } private: bool commited; + bool internal_db; system_path dir; + app_state *app; }; CMD(clone, N_("network"), N_("ADDRESS[:PORTNUMBER] [DIRECTORY]"), @@ -219,10 +226,12 @@ CMD(clone, N_("network"), N_("ADDRESS[:P // remember the initial working dir so that relative file:// db URIs will work system_path start_dir(get_current_working_dir()); - dir_cleanup_helper remove_on_fail(workspace_dir); + bool internal_db = !app.opts.dbname_given || app.opts.dbname.empty(); + + dir_cleanup_helper remove_on_fail(workspace_dir, &app, internal_db); app.create_workspace(workspace_dir); - if (!app.opts.dbname_given || app.opts.dbname.empty()) + if (internal_db) app.set_database(system_path(bookkeeping_root / ws_internal_db_file_name)); else app.set_database(app.opts.dbname); ============================================================ --- database.cc 7770e394d00b075de203a5c054350b1c44c98349 +++ database.cc 99171b1f3f3aeceb00da62cb3d74667e9be7e8bf @@ -3345,11 +3345,12 @@ database::close() void database::close() { - I(__sql); + if (__sql) + { + sqlite3_close(__sql); + __sql = 0; + } - sqlite3_close(__sql); - __sql = 0; - I(!__sql); } ============================================================ --- database.hh 6c591fe758a0dcb3706813f9fa100fae9a37c6f6 +++ database.hh ac3f29cd6d2f86ef60802f9c0674df6d2b578a7d @@ -97,15 +97,15 @@ private: void check_db_exists(); void check_db_nonexistent(); void open(); - void close(); void check_format(); public: database(system_path const & file); ~database(); - void set_app(app_state * app); + void close(); + void set_app(app_state * app); void set_filename(system_path const & file); system_path get_filename(); bool is_dbfile(any_path const & file); ============================================================ --- tests/clone_warning_with_multiple_heads/__driver__.lua 9d313a067d5944fdebbaf9595c791e5a4a1a16c4 +++ tests/clone_warning_with_multiple_heads/__driver__.lua a64e816452073997cce0f45ec970e5b42a076067 @@ -18,5 +18,6 @@ check(nodb_mtn("--branch=testbranch", "c check(nodb_mtn("--branch=testbranch", "clone", testURI, "test_dir1"), 1, false, true) +check(not exists("test_dir1")) check(qgrep(REV2, "stderr")) check(qgrep(REV3, "stderr"))