package daemon: Use CommitTransactionHandler in all cases
... also when only activating/deactivating already moved packages.
This commit is contained in:
parent
976b547224
commit
8b600ba48d
@ -297,23 +297,25 @@ struct Volume::CommitTransactionHandler {
|
|||||||
"no packages to activate or deactivate");
|
"no packages to activate or deactivate");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create an old state directory
|
_ApplyChanges(reply);
|
||||||
_CreateOldStateDirectory(reply);
|
}
|
||||||
|
|
||||||
// move packages to deactivate to old state directory
|
void HandleRequest(const PackageSet& packagesAdded,
|
||||||
_RemovePackagesToDeactivate();
|
const PackageSet& packagesRemoved)
|
||||||
|
{
|
||||||
|
// Copy package sets to fPackagesToActivate/fPackagesToDeactivate. The
|
||||||
|
// given sets are assumed to be identical to the ones specified in the
|
||||||
|
// constructor invocation (fPackagesAlreadyAdded,
|
||||||
|
// fPackagesAlreadyRemoved).
|
||||||
|
for (PackageSet::const_iterator it = packagesAdded.begin();
|
||||||
|
it != packagesAdded.end(); ++it) {
|
||||||
|
if (!fPackagesToActivate.AddItem(*it))
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
// move packages to activate to packages directory
|
fPackagesToDeactivate = packagesRemoved;
|
||||||
_AddPackagesToActivate();
|
|
||||||
|
|
||||||
// activate/deactivate packages
|
_ApplyChanges(NULL);
|
||||||
fVolume->_ChangePackageActivation(fAddedPackages, fRemovedPackages);
|
|
||||||
|
|
||||||
// removed packages have been deleted, new packages shall not be deleted
|
|
||||||
fAddedPackages.clear();
|
|
||||||
fRemovedPackages.clear();
|
|
||||||
fPackagesToActivate.MakeEmpty(false);
|
|
||||||
fPackagesToDeactivate.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Revert()
|
void Revert()
|
||||||
@ -439,6 +441,27 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _ApplyChanges(BMessage* reply)
|
||||||
|
{
|
||||||
|
// create an old state directory
|
||||||
|
_CreateOldStateDirectory(reply);
|
||||||
|
|
||||||
|
// move packages to deactivate to old state directory
|
||||||
|
_RemovePackagesToDeactivate();
|
||||||
|
|
||||||
|
// move packages to activate to packages directory
|
||||||
|
_AddPackagesToActivate();
|
||||||
|
|
||||||
|
// activate/deactivate packages
|
||||||
|
fVolume->_ChangePackageActivation(fAddedPackages, fRemovedPackages);
|
||||||
|
|
||||||
|
// removed packages have been deleted, new packages shall not be deleted
|
||||||
|
fAddedPackages.clear();
|
||||||
|
fRemovedPackages.clear();
|
||||||
|
fPackagesToActivate.MakeEmpty(false);
|
||||||
|
fPackagesToDeactivate.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void _CreateOldStateDirectory(BMessage* reply)
|
void _CreateOldStateDirectory(BMessage* reply)
|
||||||
{
|
{
|
||||||
// construct a nice name from the current date and time
|
// construct a nice name from the current date and time
|
||||||
@ -1187,15 +1210,29 @@ Volume::ProcessPendingPackageActivationChanges()
|
|||||||
if (!HasPendingPackageActivationChanges())
|
if (!HasPendingPackageActivationChanges())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// perform the request
|
||||||
|
CommitTransactionHandler handler(this, fPackagesToBeActivated,
|
||||||
|
fPackagesToBeDeactivated);
|
||||||
|
int32 error;
|
||||||
try {
|
try {
|
||||||
_ChangePackageActivation(fPackagesToBeActivated,
|
handler.HandleRequest(fPackagesToBeActivated, fPackagesToBeDeactivated);
|
||||||
fPackagesToBeDeactivated);
|
error = B_DAEMON_OK;
|
||||||
} catch (Exception& exception) {
|
} catch (Exception& exception) {
|
||||||
|
error = exception.Error();
|
||||||
ERROR("Volume::ProcessPendingPackageActivationChanges(): package "
|
ERROR("Volume::ProcessPendingPackageActivationChanges(): package "
|
||||||
"activation failed: %s\n", exception.ToString().String());
|
"activation failed: %s\n", exception.ToString().String());
|
||||||
|
// TODO: Notify the user!
|
||||||
|
} catch (std::bad_alloc& exception) {
|
||||||
|
error = B_NO_MEMORY;
|
||||||
|
ERROR("Volume::ProcessPendingPackageActivationChanges(): package "
|
||||||
|
"activation failed: out of memory\n");
|
||||||
// TODO: Notify the user!
|
// TODO: Notify the user!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// revert on error
|
||||||
|
if (error != B_DAEMON_OK)
|
||||||
|
handler.Revert();
|
||||||
|
|
||||||
// clear the activation/deactivation sets in any event
|
// clear the activation/deactivation sets in any event
|
||||||
fPackagesToBeActivated.clear();
|
fPackagesToBeActivated.clear();
|
||||||
fPackagesToBeDeactivated.clear();
|
fPackagesToBeDeactivated.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user