diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-10 08:12:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-10 08:12:50 +0200 |
commit | 4e3faacbc3c27e1d01ca95697b34db82cdecdb9d (patch) | |
tree | 5144d4bddbb376318fcaf20dafa0c391ddce93b1 /bpkg/pkg-purge.cxx | |
parent | 803acc23f8cea3079681e9e624702e104adfd775 (diff) |
Implement --replace|-r mode for pkg-fetch
Diffstat (limited to 'bpkg/pkg-purge.cxx')
-rw-r--r-- | bpkg/pkg-purge.cxx | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/bpkg/pkg-purge.cxx b/bpkg/pkg-purge.cxx index 5e14a2b..91c4c5b 100644 --- a/bpkg/pkg-purge.cxx +++ b/bpkg/pkg-purge.cxx @@ -17,6 +17,40 @@ using namespace butl; namespace bpkg { void + pkg_purge_archive (const dir_path& c, + transaction& t, + const shared_ptr<selected_package>& p) + { + assert (p->purge_archive && p->state != package_state::broken); + + tracer trace ("pkg_purge_archive"); + + database& db (t.database ()); + tracer_guard tg (db, trace); + + path a (p->archive->absolute () ? *p->archive : c / *p->archive); + + try + { + if (exists (a)) + rm (a); + + p->archive = nullopt; + p->purge_archive = false; + } + catch (const failed&) + { + p->state = package_state::broken; + db.update (p); + t.commit (); + + info << "package " << p->name << " is now broken; " + << "use 'pkg-purge --force' to remove"; + throw; + } + } + + void pkg_purge (const pkg_purge_options& o, cli::scanner& args) { tracer trace ("pkg_purge"); @@ -131,31 +165,12 @@ namespace bpkg // if (p->purge_archive && !o.keep ()) { - path a (p->archive->absolute () ? *p->archive : c / *p->archive); - if (p->state != package_state::broken) - { - try - { - if (exists (a)) - rm (a); - - p->archive = nullopt; - p->purge_archive = false; - } - catch (const failed&) - { - p->state = package_state::broken; - db.update (p); - t.commit (); - - info << "package " << n << " is now broken; " - << "use 'pkg-purge --force' to remove"; - throw; - } - } + pkg_purge_archive (c, t, p); else { + path a (p->archive->absolute () ? *p->archive : c / *p->archive); + if (exists (a)) fail << "broken package " << n << " archive still exists" << info << "remove " << a << " manually then re-run pkg-purge"; |