aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-10-24 08:23:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-10-24 08:23:42 +0200
commit44d5647b4b92089fc90195b41373f6b99dc5c42c (patch)
tree8b11ace1051875e9d7ffe910885ca2790f2d1ca1
parent282361b57f66b59a50ed3d073b46c7189c9553ee (diff)
Close database as soon as possible
This becomes important if we trigger a recursive implicit sync that uses the same database (e.g., in a build system module project).
-rw-r--r--bdep/build.txx14
-rw-r--r--bdep/ci.cxx5
-rw-r--r--bdep/deinit.cxx18
-rw-r--r--bdep/fetch.cxx14
-rw-r--r--bdep/publish.cxx5
5 files changed, 38 insertions, 18 deletions
diff --git a/bdep/build.txx b/bdep/build.txx
index 1cd5fff..b83aa9c 100644
--- a/bdep/build.txx
+++ b/bdep/build.txx
@@ -45,11 +45,17 @@ namespace bdep
const dir_path& prj (pp.project);
- database db (open (prj, trace));
+ // Load the configurations without keeping the database open longer
+ // than necessary.
+ //
+ configurations cfgs;
+ {
+ database db (open (prj, trace));
- transaction t (db.begin ());
- configurations cfgs (find_configurations (o, prj, t));
- t.commit ();
+ transaction t (db.begin ());
+ cfgs = find_configurations (o, prj, t);
+ t.commit ();
+ }
// If specified, verify packages are present in each configuration.
//
diff --git a/bdep/ci.cxx b/bdep/ci.cxx
index 08f2578..81db678 100644
--- a/bdep/ci.cxx
+++ b/bdep/ci.cxx
@@ -200,10 +200,13 @@ namespace bdep
false /* load_packages */));
const dir_path& prj (pp.project);
- database db (open (prj, trace));
shared_ptr<configuration> cfg;
{
+ // Don't keep the database open longer than necessary.
+ //
+ database db (open (prj, trace));
+
transaction t (db.begin ());
configurations cfgs (find_configurations (o, prj, t));
t.commit ();
diff --git a/bdep/deinit.cxx b/bdep/deinit.cxx
index 735b746..18acf52 100644
--- a/bdep/deinit.cxx
+++ b/bdep/deinit.cxx
@@ -111,14 +111,16 @@ namespace bdep
database db (open (prj, trace));
- transaction t (db.begin ());
- configurations cfgs (
- find_configurations (o,
- prj,
- t,
- true /* fallback_default */,
- !force /* validate */));
- t.commit ();
+ configurations cfgs;
+ {
+ transaction t (db.begin ());
+ cfgs = find_configurations (o,
+ prj,
+ t,
+ true /* fallback_default */,
+ !force /* validate */);
+ t.commit ();
+ }
// If specified, verify packages are present in each configuration.
//
diff --git a/bdep/fetch.cxx b/bdep/fetch.cxx
index 7a88106..3527e51 100644
--- a/bdep/fetch.cxx
+++ b/bdep/fetch.cxx
@@ -33,11 +33,17 @@ namespace bdep
tracer trace ("fetch");
dir_path prj (find_project (o));
- database db (open (prj, trace));
- transaction t (db.begin ());
- configurations cfgs (find_configurations (o, prj, t));
- t.commit ();
+ configurations cfgs;
+ {
+ // Don't keep the database open longer than necessary.
+ //
+ database db (open (prj, trace));
+
+ transaction t (db.begin ());
+ cfgs = find_configurations (o, prj, t);
+ t.commit ();
+ }
bool first (true);
for (const shared_ptr<configuration>& c: cfgs)
diff --git a/bdep/publish.cxx b/bdep/publish.cxx
index 1fcc942..ab58025 100644
--- a/bdep/publish.cxx
+++ b/bdep/publish.cxx
@@ -807,12 +807,15 @@ namespace bdep
true /* load_packages */));
const dir_path& prj (pp.project);
- database db (open (prj, trace));
// We need a single configuration to prepare package distribution.
//
shared_ptr<configuration> cfg;
{
+ // Don't keep the database open longer than necessary.
+ //
+ database db (open (prj, trace));
+
transaction t (db.begin ());
configurations cfgs (find_configurations (o, prj, t));
t.commit ();