diff options
-rw-r--r-- | pkgadd.cc | 10 | ||||
-rw-r--r-- | pkgutil.cc | 7 | ||||
-rw-r--r-- | pkgutil.h | 2 |
3 files changed, 15 insertions, 4 deletions
@@ -103,7 +103,15 @@ void pkgadd::run(int argc, char** argv) db_add_pkg(package.first, package.second); db_commit(); - pkg_install(o_package, keep_list, non_install_files); + try { + pkg_install(o_package, keep_list, non_install_files, installed); + } catch (runtime_error&) { + if (!installed) { + db_rm_pkg(package.first); + db_commit(); + throw runtime_error("failed"); + } + } ldconfig(); } } @@ -383,7 +383,7 @@ pair<string, pkgutil::pkginfo_t> pkgutil::pkg_open(const string& filename) const return result; } -void pkgutil::pkg_install(const string& filename, const set<string>& keep_list, const set<string>& non_install_list) const +void pkgutil::pkg_install(const string& filename, const set<string>& keep_list, const set<string>& non_install_list, bool upgrade) const { struct archive* archive; struct archive_entry* entry; @@ -435,9 +435,12 @@ void pkgutil::pkg_install(const string& filename, const set<string>& keep_list, if (archive_read_extract(archive, entry, flags) != ARCHIVE_OK) { // If a file fails to install we just print an error message and - // continue trying to install the rest of the package. + // continue trying to install the rest of the package, + // unless this is not an upgrade. const char* msg = archive_error_string(archive); cerr << utilname << ": could not install " + archive_filename << ": " << msg << endl; + if (!upgrade) + throw runtime_error("extract error: " + archive_filename + ": " + msg); continue; } @@ -71,7 +71,7 @@ protected: // Tar.gz pair<string, pkginfo_t> pkg_open(const string& filename) const; - void pkg_install(const string& filename, const set<string>& keep_list, const set<string>& non_install_files) const; + void pkg_install(const string& filename, const set<string>& keep_list, const set<string>& non_install_files, bool upgrade) const; void pkg_footprint(string& filename) const; void ldconfig() const; |