From b94b5381f68061121c22f2786ba1fa774f1ee6f6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 30 Jul 2016 17:25:23 +0200 Subject: Convert to use canonical directory separators --- bpkg/auth.cxx | 20 ++++++++------------ bpkg/cfg-create.cxx | 7 ++++--- bpkg/database.cxx | 11 +---------- bpkg/pkg-command.cxx | 6 ++++-- bpkg/pkg-configure.cxx | 8 +++++--- bpkg/pkg-disfigure.cxx | 14 ++++++++------ bpkg/rep-create.cxx | 2 +- bpkg/types | 16 ++-------------- bpkg/utility | 5 +++++ bpkg/utility.cxx | 7 ++++++- 10 files changed, 44 insertions(+), 52 deletions(-) diff --git a/bpkg/auth.cxx b/bpkg/auth.cxx index a9eaa76..2c5d3d8 100644 --- a/bpkg/auth.cxx +++ b/bpkg/auth.cxx @@ -37,16 +37,18 @@ namespace bpkg // Construct the prefix as a relative repository location. // - string p ("."); + dir_path p; for (auto i (rl.path ().rbegin ()), e (rl.path ().rend ()); i != e; ++i) { const string& c (*i); if (!c.empty () && c.find_first_not_of ("1234567890") == string::npos) break; - p = "../" + p; + p /= ".."; } + p /= "."; + // If this is a remote location then use the canonical name prefix. For // a local location this doesn't always work. Consider: // @@ -57,13 +59,9 @@ namespace bpkg // use the location rather than the name prefix. // if (rl.remote ()) - return repository_location (p, rl).canonical_name (); + return repository_location (p.posix_string (), rl).canonical_name (); else - { - path lp (rl.path () / path (p)); - lp.normalize (); - return lp.string (); - } + return (rl.path () / p).normalize ().string (); } // Authenticate a dummy certificate. If trusted, it will authenticate all @@ -512,8 +510,6 @@ namespace bpkg return cert; } - static const dir_path certs_dir (".bpkg/certs"); - // Authenticate a certificate with the database. First check if it is // already authenticated. If not, authenticate and add to the database. // @@ -579,7 +575,7 @@ namespace bpkg fail << "--trust-yes and --trust-no are mutually exclusive"; if (conf != nullptr && conf->empty ()) - conf = dir_exists (path (".bpkg")) ? ¤t_dir : nullptr; + conf = dir_exists (bpkg_dir) ? ¤t_dir : nullptr; assert (conf == nullptr || !conf->empty ()); @@ -619,7 +615,7 @@ namespace bpkg tracer trace ("authenticate_repository"); if (conf != nullptr && conf->empty ()) - conf = dir_exists (path (".bpkg")) ? ¤t_dir : nullptr; + conf = dir_exists (bpkg_dir) ? ¤t_dir : nullptr; assert (conf == nullptr || !conf->empty ()); diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index b5b1f41..94a7764 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -136,12 +136,13 @@ namespace bpkg // Configure. // - // Run quiet. - run_b (o, c, "configure('" + c.string () + "/')", true, vars); + // Run quiet. Use path representation to get canonical trailing slash. + // + run_b (o, c, "configure('" + c.representation () + "')", true, vars); // Create .bpkg/. // - mk (c / dir_path (".bpkg")); + mk (c / bpkg_dir); // Create the database. // diff --git a/bpkg/database.cxx b/bpkg/database.cxx index bffba02..6eec6f8 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -21,16 +21,7 @@ namespace bpkg { tracer trace ("open"); - // @@ Shouldn't we create database file in d / ".bpkg" directory ? - // - // @@ Yes, let's do it. Also perhaps downloaded packages as well? - // We might as well. - // - // @@ Don't think would be natural to keep package archives there as, the - // user should see which packages are downloaded without need to look - // into the "hidden" directory. - // - path f (d / path (".bpkg/bpkg.sqlite3")); + path f (d / bpkg_dir / "bpkg.sqlite3"); if (!create && !exists (f)) fail << d << " does not look like a bpkg configuration directory"; diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 4f5478d..ba1b548 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -62,9 +62,11 @@ namespace bpkg if (bspec.back () != '(') bspec += ' '; + // Use path representation to get canonical trailing slash. + // + bspec += '\''; + bspec += out_root.representation (); bspec += '\''; - bspec += out_root.string (); - bspec += "/'"; if (!pv.vars.empty ()) run (pv.vars); // Run this package. diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 6027269..16eefd2 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -104,12 +104,14 @@ namespace bpkg // string bspec; + // Use path representation to get canonical trailing slash. + // if (src_root == out_root) - bspec = "configure('" + out_root.string () + "/')"; + bspec = "configure('" + out_root.representation () + "')"; else bspec = "configure('" + - src_root.string () + "/'@'" + - out_root.string () + "/')"; + src_root.representation () + "'@'" + + out_root.representation () + "')"; l4 ([&]{trace << "buildspec: " << bspec;}); diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index cb3e657..de9b681 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -72,10 +72,13 @@ namespace bpkg // string bspec; + // Use path representation to get canonical trailing slash. + // + const string& rep (out_root.representation ()); + if (p->state == package_state::configured) { - bspec = "clean('" + out_root.string () + "/') " - "disfigure('" + out_root.string () + "/')"; + bspec = "clean('" + rep + "') " "disfigure('" + rep + "')"; } else { @@ -84,11 +87,10 @@ namespace bpkg // partially configured one. // if (src_root == out_root) - bspec = "disfigure('" + out_root.string () + "/')"; + bspec = "disfigure('" + rep + "')"; else - bspec = "disfigure('" + - src_root.string () + "/'@'" + - out_root.string () + "/')"; + bspec = "disfigure('" + src_root.representation () + "'@'" + + rep + "')"; } l4 ([&]{trace << "buildspec: " << bspec;}); diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index 323003b..2d682f8 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -180,7 +180,7 @@ namespace bpkg dir_path d (args.more () ? args.next () : "."); if (d.empty ()) - throw invalid_path (d.string ()); + throw invalid_path (d.representation ()); l4 ([&]{trace << "creating repository in " << d;}); diff --git a/bpkg/types b/bpkg/types index aa88701..2e03675 100644 --- a/bpkg/types +++ b/bpkg/types @@ -81,22 +81,10 @@ namespace bpkg using paths = std::vector; using dir_paths = std::vector; - // Custom path printing. + // Custom path printing (with trailing slash for directories). // inline ostream& - operator<< (ostream& os, const path& p) {return os << p.string ();} - - inline ostream& - operator<< (ostream& os, const dir_path& p) - { - const string& s (p.string ()); - os << s; - - if (!s.empty () && !dir_path::traits::is_separator (s.back ())) - os << dir_path::traits::directory_separator; - - return os; - } + operator<< (ostream& os, const path& p) {return os << p.representation ();} } #endif // BPKG_TYPES diff --git a/bpkg/utility b/bpkg/utility index 7bb6111..901fbbd 100644 --- a/bpkg/utility +++ b/bpkg/utility @@ -34,6 +34,11 @@ namespace bpkg // using butl::reverse_iterate; + // Widely-used paths. + // + extern const dir_path bpkg_dir; // .bpkg/ + extern const dir_path certs_dir; // .bpkg/certs/ + // Y/N prompt. The def argument, if specified, should be either 'y' // or 'n'. It is used as the default answer, in case the user just // hits enter. Issue diagnostics and throw failed if no answer could diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx index 57a299b..9bf1a5a 100644 --- a/bpkg/utility.cxx +++ b/bpkg/utility.cxx @@ -16,6 +16,9 @@ using namespace butl; namespace bpkg { + const dir_path bpkg_dir (".bpkg"); + const dir_path certs_dir (dir_path (bpkg_dir) /= "certs"); + bool yn_prompt (const char* prompt, char def) { @@ -229,7 +232,9 @@ namespace bpkg // if (v[0] != '!') { - storage.push_back (c.string () + "/:" + v); + // Use path representation to get canonical trailing slash. + // + storage.push_back (c.representation () + ':' + v); args.push_back (storage.back ().c_str ()); } else -- cgit v1.1