package_daemon: Try to use the old activated-packages file time for the state name.

Using the current time can be confusing when looking at packages or
the bootloader, as the time represents whenever the new state was made,
not when the old state was.

When there is no activated-packages file, we just use the current time
anyway. This means that on newly created systems, the first two states
will have the same time, and the second will have an extra "-1" on the
end of its name to distinguish it (if for some reason the activated
file retains its time, then you'll get "-2", etc.)

Change-Id: I128764ae4650a3433e2584f3ed154b04cf850b19
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7543
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Augustin Cavalier 2024-03-21 16:38:33 -04:00 committed by waddlesplash
parent 6ac10b2f4b
commit 76142a9377

View File

@ -452,11 +452,22 @@ CommitTransactionHandler::_ApplyChanges()
void
CommitTransactionHandler::_CreateOldStateDirectory()
{
// construct a nice name from the current date and time
time_t nowSeconds = time(NULL);
time_t stateTime = 0;
{
// use the modification time of the old activations file, if possible
BFile oldActivationFile;
BEntry oldActivationEntry;
if (_OpenPackagesFile(RelativePath(kAdminDirectoryName), kActivationFileName,
B_READ_ONLY, oldActivationFile, &oldActivationEntry) != B_OK
|| oldActivationEntry.GetModificationTime(&stateTime) != B_OK) {
stateTime = time(NULL);
}
}
// construct a nice name from the date and time
struct tm now;
BString baseName;
if (localtime_r(&nowSeconds, &now) != NULL) {
if (localtime_r(&stateTime, &now) != NULL) {
baseName.SetToFormat("state_%d-%02d-%02d_%02d:%02d:%02d",
1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour,
now.tm_min, now.tm_sec);