@@ -1749,74 +1749,60 @@ void ModulePackageContainer::Impl::addVersion2Modules()
17491749
17501750void ModulePackageContainer::updateFailSafeData ()
17511751{
1752- auto activatedModules = pImpl->activatedModules .get ();
1753- if (!activatedModules) {
1754- return ;
1755- }
1756- std::vector<ModulePackage *> latest = pImpl->getLatestActiveEnabledModules ();
1757-
17581752 auto fileNames = getYamlFilenames (pImpl->persistDir .c_str ());
1759- Map map;
1760- map_init (&map, fileNames.size ());
1761- auto begin = fileNames.begin ();
1762- auto end = fileNames.end ();
1763- if (g_mkdir_with_parents (pImpl->persistDir .c_str (), 0755 ) == -1 ) {
1764- const char * errTxt = strerror (errno);
1765- auto logger (Log::getLogger ());
1766- logger->debug (tfm::format (
1767- _ (" Unable to create directory \" %s\" for modular Fail Safe data: %s" ),
1768- pImpl->persistDir .c_str (), errTxt));
1769- }
17701753
1771- // Update FailSafe data
1772- for (auto modulePackage: latest) {
1773- std::ostringstream ss;
1774- ss << modulePackage->getNameStream ();
1775- ss << " :" << modulePackage->getArch () << " .yaml" ;
1776- auto fileName = ss.str ();
1777- auto low = std::lower_bound (begin, end, fileName);
1778- if (low != end && fileName == *low) {
1779- MAPSET (&map, low - begin);
1780- }
1781- if (modulePackage->getRepoID () == LIBDNF_MODULE_FAIL_SAFE_REPO_NAME) {
1782- continue ;
1783- }
1784- g_autofree gchar * filePath = g_build_filename (pImpl->persistDir .c_str (), fileName.c_str (),
1785- NULL );
1786- if (!updateFile (filePath, modulePackage->getYaml ().c_str ())) {
1754+ if (pImpl->activatedModules ) {
1755+ std::vector<ModulePackage *> latest = pImpl->getLatestActiveEnabledModules ();
1756+
1757+ auto begin = fileNames.begin ();
1758+ auto end = fileNames.end ();
1759+ if (g_mkdir_with_parents (pImpl->persistDir .c_str (), 0755 ) == -1 ) {
1760+ const char * errTxt = strerror (errno);
17871761 auto logger (Log::getLogger ());
17881762 logger->debug (tfm::format (
1789- _ (" Unable to save a modular Fail Safe data to '%s'" ), filePath));
1763+ _ (" Unable to create directory \" %s\" for modular Fail Safe data: %s" ),
1764+ pImpl->persistDir .c_str (), errTxt));
17901765 }
1791- }
17921766
1793- // Remove files from not enabled modules
1794- for (unsigned int index = 0 ; index < fileNames.size (); ++index) {
1795- if (!MAPTST (&map, index)) {
1796- auto fileName = fileNames[index];
1797- auto first = fileName.find (" :" );
1798- if (first == std::string::npos || first == 0 ) {
1767+ // Update FailSafe data
1768+ for (auto modulePackage: latest) {
1769+ std::ostringstream ss;
1770+ ss << modulePackage->getNameStream ();
1771+ ss << " :" << modulePackage->getArch () << " .yaml" ;
1772+ auto fileName = ss.str ();
1773+ if (modulePackage->getRepoID () == LIBDNF_MODULE_FAIL_SAFE_REPO_NAME) {
17991774 continue ;
18001775 }
1801- std::string moduleName = fileName.substr ( 0 , first );
1802- auto second = fileName. find ( " : " , ++first);
1803- if (second == std::string::npos || first == second) {
1804- continue ;
1776+ g_autofree gchar * filePath = g_build_filename (pImpl-> persistDir . c_str (), fileName.c_str (), NULL );
1777+ if (! updateFile (filePath, modulePackage-> getYaml (). c_str ())) {
1778+ auto logger ( Log::getLogger ());
1779+ logger-> debug ( tfm::format ( _ ( " Unable to save a modular Fail Safe data to '%s' " ), filePath)) ;
18051780 }
1806- std::string moduleStream = fileName.substr (first, second - first);
1781+ }
1782+ }
18071783
1808- if (!isEnabled (moduleName, moduleStream)) {
1809- g_autofree gchar * file = g_build_filename (
1810- pImpl->persistDir .c_str (), fileNames[index].c_str (), NULL );
1811- if (remove (file)) {
1812- auto logger (Log::getLogger ());
1813- logger->debug (tfm::format (
1814- _ (" Unable to remove a modular Fail Safe data in '%s'" ), file));
1815- }
1784+ // Remove files from not enabled modules
1785+ for (unsigned int index = 0 ; index < fileNames.size (); ++index) {
1786+ auto fileName = fileNames[index];
1787+ auto first = fileName.find (" :" );
1788+ if (first == std::string::npos || first == 0 ) {
1789+ continue ;
1790+ }
1791+ std::string moduleName = fileName.substr (0 , first);
1792+ auto second = fileName.find (" :" , ++first);
1793+ if (second == std::string::npos || first == second) {
1794+ continue ;
1795+ }
1796+ std::string moduleStream = fileName.substr (first, second - first);
1797+
1798+ if (!isEnabled (moduleName, moduleStream)) {
1799+ g_autofree gchar * file = g_build_filename (pImpl->persistDir .c_str (), fileNames[index].c_str (), NULL );
1800+ if (remove (file)) {
1801+ auto logger (Log::getLogger ());
1802+ logger->debug (tfm::format (_ (" Unable to remove a modular Fail Safe data in '%s'" ), file));
18161803 }
18171804 }
18181805 }
1819- map_free (&map);
18201806}
18211807
18221808void ModulePackageContainer::applyObsoletes (){
0 commit comments