diff --git a/src/common/commonutils/PackageUtils.c b/src/common/commonutils/PackageUtils.c index b0e665a21..8bc1f36d9 100644 --- a/src/common/commonutils/PackageUtils.c +++ b/src/common/commonutils/PackageUtils.c @@ -17,6 +17,7 @@ static bool g_tdnfIsPresent = false; static bool g_dnfIsPresent = false; static bool g_yumIsPresent = false; static bool g_zypperIsPresent = false; +static bool g_aptGetUpdateExecuted = false; int IsPresent(const char* what, void* log) { @@ -178,6 +179,27 @@ int CheckPackageNotInstalled(const char* packageName, char** reason, void* log) return result; } +void AptGetUpdateOnce(void* log) +{ + const char* command = "apt-get update"; + int status = 0; + if (g_aptGetUpdateExecuted) + { + return; + } + + if (0 == (status = ExecuteCommand(NULL, command, false, false, 0, 0, NULL, NULL, log))) + { + OsConfigLogInfo(log, "AptGetUpdateOnce: apt-get update was successful"); + g_aptGetUpdateExecuted = true; + } + else + { + OsConfigLogError(log, "AptGetUpdateOnce: apt-get update failed with %d", status); + } + +} + int InstallOrUpdatePackage(const char* packageName, void* log) { const char* commandTemplate = "%s install -y %s"; @@ -187,6 +209,7 @@ int InstallOrUpdatePackage(const char* packageName, void* log) if (g_aptGetIsPresent) { + AptGetUpdateOnce(log); status = CheckOrInstallPackage(commandTemplate, g_aptGet, packageName, log); } else if (g_tdnfIsPresent)