better return value for uninstall()

This commit is contained in:
David Rose 2010-06-10 00:30:50 +00:00
parent 1b02e24408
commit 5b4d31c9e6
3 changed files with 29 additions and 7 deletions

View File

@ -1495,8 +1495,17 @@ auth_finished_main_thread() {
// normally called by JavaScript, via // normally called by JavaScript, via
// P3DMainObject::call_uninstall(). // P3DMainObject::call_uninstall().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DInstance:: bool P3DInstance::
uninstall_packages() { uninstall_packages() {
if (_packages.empty()) {
// If we have no packages (for instance, because we're untrusted),
// we can't uninstall anything.
nout << "Uninstall failed: no packages.\n";
return false;
}
nout << "Uninstalling " << _packages.size() << " packages\n";
Packages::const_iterator pi; Packages::const_iterator pi;
for (pi = _packages.begin(); pi != _packages.end(); ++pi) { for (pi = _packages.begin(); pi != _packages.end(); ++pi) {
P3DPackage *package = (*pi); P3DPackage *package = (*pi);
@ -1514,6 +1523,8 @@ uninstall_packages() {
nout << "Cleaning up start directory " << start_dir << "\n"; nout << "Cleaning up start directory " << start_dir << "\n";
inst_mgr->delete_directory_recursively(start_dir); inst_mgr->delete_directory_recursively(start_dir);
} }
return true;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -1526,8 +1537,15 @@ uninstall_packages() {
// is normally called by JavaScript, via // is normally called by JavaScript, via
// P3DMainObject::call_uninstall(). // P3DMainObject::call_uninstall().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DInstance:: bool P3DInstance::
uninstall_host() { uninstall_host() {
if (_packages.empty()) {
// If we have no packages (for instance, because we're untrusted),
// we can't uninstall anything.
nout << "Uninstall failed: no packages.\n";
return false;
}
uninstall_packages(); uninstall_packages();
// Collect the set of hosts referenced by this instance. // Collect the set of hosts referenced by this instance.
@ -1540,6 +1558,7 @@ uninstall_host() {
hosts.insert(package->get_host()); hosts.insert(package->get_host());
} }
} }
nout << "Uninstalling " << hosts.size() << " hosts\n";
// Uninstall all of them. // Uninstall all of them.
set<P3DHost *>::iterator hi; set<P3DHost *>::iterator hi;
@ -1547,6 +1566,8 @@ uninstall_host() {
P3DHost *host = (*hi); P3DHost *host = (*hi);
host->uninstall(); host->uninstall();
} }
return true;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -119,8 +119,8 @@ public:
void auth_finished_sub_thread(); void auth_finished_sub_thread();
void auth_finished_main_thread(); void auth_finished_main_thread();
void uninstall_packages(); bool uninstall_packages();
void uninstall_host(); bool uninstall_host();
private: private:
class ImageDownload : public P3DFileDownload { class ImageDownload : public P3DFileDownload {

View File

@ -709,12 +709,13 @@ call_uninstall(P3D_object *params[], int num_params) {
if (_inst != NULL) { if (_inst != NULL) {
nout << "uninstall " << mode << " for " << _inst << "\n"; nout << "uninstall " << mode << " for " << _inst << "\n";
bool success = false;
if (mode == "host") { if (mode == "host") {
_inst->uninstall_host(); success = _inst->uninstall_host();
} else { } else {
_inst->uninstall_packages(); success = _inst->uninstall_packages();
} }
return inst_mgr->new_bool_object(true); return inst_mgr->new_bool_object(success);
} }
nout << "couldn't uninstall; no instance.\n"; nout << "couldn't uninstall; no instance.\n";