aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-07 15:49:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-07 15:49:44 +0200
commit8f94aaa067426a259f5396abdaf4945671799b5c (patch)
treefb64d4135cab2d36d2582dd7baf222e76e4d3bc5
parent2858e5f80f836862400bf814ef1b2dcb0ff8a74e (diff)
Various fixes for rep-create
-rw-r--r--bpkg/buildfile2
-rw-r--r--bpkg/rep-create.cxx22
-rw-r--r--bpkg/utility19
-rw-r--r--bpkg/utility.cxx46
4 files changed, 83 insertions, 6 deletions
diff --git a/bpkg/buildfile b/bpkg/buildfile
index 7bcdab5..0e03e93 100644
--- a/bpkg/buildfile
+++ b/bpkg/buildfile
@@ -7,7 +7,7 @@ using cli
import libs = libbutl%lib{butl}
import libs += libbpkg%lib{bpkg}
-exe{bpkg}: cxx{diagnostics} cli.cxx{common-options} \
+exe{bpkg}: cxx{diagnostics utility} cli.cxx{common-options} \
cxx{bpkg} cli.cxx{bpkg-options} \
cxx{help} cli.cxx{help-options} \
cxx{rep-create} cli.cxx{rep-create-options} \
diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx
index 1b8712a..bfa4776 100644
--- a/bpkg/rep-create.cxx
+++ b/bpkg/rep-create.cxx
@@ -9,6 +9,7 @@
#include <cassert>
#include <fstream>
#include <iostream>
+#include <system_error>
#include <butl/process>
#include <butl/fdstream>
@@ -19,6 +20,7 @@
#include <bpkg/manifest-serializer>
#include <bpkg/types>
+#include <bpkg/utility>
#include <bpkg/diagnostics>
using namespace std;
@@ -32,10 +34,11 @@ namespace bpkg
static void
collect (package_map& map, const dir_path& d, const dir_path& root)
+ try
{
tracer trace ("collect");
- for (const dir_entry& de: dir_iterator (d))
+ for (const dir_entry& de: dir_iterator (d)) // system_error
{
path p (de.path ());
@@ -47,7 +50,7 @@ namespace bpkg
continue;
}
- switch (de.type ()) // Follow symlinks.
+ switch (de.type ()) // Follow symlinks, system_error.
{
case entry_type::directory:
{
@@ -174,6 +177,11 @@ namespace bpkg
}
}
}
+ catch (const system_error& e)
+ {
+ error << "unable to scan directory " << d << ": " << e.what ();
+ throw failed ();
+ }
void
rep_create (const rep_create_options&, cli::scanner& args)
@@ -192,7 +200,7 @@ namespace bpkg
//
path rf (d / path ("repositories"));
- if (!file_exists (rf))
+ if (!exists (rf))
fail << "file " << rf << " does not exist";
try
@@ -249,13 +257,17 @@ namespace bpkg
{
fail << "unable to save manifest: " << e.description;
}
- catch (const ifdstream::failure&)
+ catch (const ofstream::failure&)
{
fail << "unable to write to " << p;
}
if (verb)
- text << pm.size () << " package(s)";
+ {
+ d.complete ();
+ d.normalize ();
+ text << pm.size () << " package(s) in " << d;
+ }
}
catch (const invalid_path& e)
{
diff --git a/bpkg/utility b/bpkg/utility
new file mode 100644
index 0000000..9c6688f
--- /dev/null
+++ b/bpkg/utility
@@ -0,0 +1,19 @@
+// file : bpkg/utility -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BPKG_UTILITY
+#define BPKG_UTILITY
+
+#include <bpkg/types>
+
+namespace bpkg
+{
+ bool
+ exists (const path&);
+
+ bool
+ exists (const dir_path&);
+}
+
+#endif // BPKG_UTILITY
diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx
new file mode 100644
index 0000000..c274563
--- /dev/null
+++ b/bpkg/utility.cxx
@@ -0,0 +1,46 @@
+// file : bpkg/utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/utility>
+
+#include <system_error>
+
+#include <butl/filesystem>
+
+#include <bpkg/types>
+#include <bpkg/diagnostics>
+
+using namespace std;
+using namespace butl;
+
+namespace bpkg
+{
+ bool
+ exists (const path& f)
+ {
+ try
+ {
+ return file_exists (f);
+ }
+ catch (const system_error& e)
+ {
+ error << "unable to stat path " << f << ": " << e.what ();
+ throw failed ();
+ }
+ }
+
+ bool
+ exists (const dir_path& d)
+ {
+ try
+ {
+ return file_exists (d);
+ }
+ catch (const system_error& e)
+ {
+ error << "unable to stat path " << d << ": " << e.what ();
+ throw failed ();
+ }
+ }
+}