aboutsummaryrefslogtreecommitdiff
path: root/build2/depdb.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-11-21 11:39:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-11-21 11:39:48 +0200
commit8456beeb0529b8dde7f4eea9a949c1c4f91a6120 (patch)
tree880daba940330890e45d84da350c8dc2d18fe32e /build2/depdb.cxx
parentc7dabff3aaab59649fba8dc18ae5dadf0c0b8f20 (diff)
Diagnose failure to open depdb
The cause is often a missing fsdir{} if the user tries to stash the target in a subdirectory.
Diffstat (limited to 'build2/depdb.cxx')
-rw-r--r--build2/depdb.cxx47
1 files changed, 32 insertions, 15 deletions
diff --git a/build2/depdb.cxx b/build2/depdb.cxx
index ee96efa..c041a0a 100644
--- a/build2/depdb.cxx
+++ b/build2/depdb.cxx
@@ -6,6 +6,8 @@
#include <libbutl/filesystem.mxx> // file_mtime()
+#include <build2/diagnostics.hxx>
+
using namespace std;
using namespace butl;
@@ -15,31 +17,46 @@ namespace build2
depdb (const path& f)
: mtime_ (file_mtime (f)), touch_ (false)
{
- fs_.exceptions (fstream::failbit | fstream::badbit);
+ fstream::openmode om (fstream::out | fstream::binary);
+ fstream::iostate em (fstream::badbit);
- if (mtime_ != timestamp_nonexistent)
+ if (mtime_ == timestamp_nonexistent)
+ {
+ mtime_ = timestamp_unknown;
+ state_ = state::write;
+ em |= fstream::failbit;
+ }
+ else
{
- // Open an existing file.
- //
- fs_.open (f.string (), fstream::in | fstream::out | fstream::binary);
state_ = state::read;
- fs_.exceptions (fstream::badbit);
+ om |= fstream::in;
+ }
- // Read the database format version.
- //
+ fs_.open (f.string (), om);
+ if (!fs_.is_open ())
+ {
+ bool c (state_ == state::write);
+
+ diag_record dr (fail);
+ dr << "unable to " << (c ? "create" : "open") << ' ' << f;
+
+ if (c)
+ dr << info << "did you forget to add fsdir{} prerequisite for "
+ << "output directory?";
+ }
+
+ fs_.exceptions (em);
+
+ // Read/write the database format version.
+ //
+ if (state_ == state::read)
+ {
string* l (read ());
if (l == nullptr || *l != "1")
write ('1');
}
else
- {
- fs_.open (f.string (), fstream::out | fstream::binary);
-
- state_ = state::write;
- mtime_ = timestamp_unknown;
-
write ('1');
- }
}
void depdb::