diff --git a/src/ek2/layouts/std.cxx b/src/ek2/layouts/std.cxx index 2354b62..9daaa9f 100644 --- a/src/ek2/layouts/std.cxx +++ b/src/ek2/layouts/std.cxx @@ -100,6 +100,7 @@ bool StdLayout::find_kernels() { const std::string& boot_path = opts_.boot_path; const std::string& module_path = opts_.module_path; + const bool ignore_module_dir = opts_.ignore_module_dir; std::unordered_map file_map; typedef std::unordered_mapread()) - { - // skip ., .. and all hidden files - if (modules_dir_->filename()[0] == '.') - continue; - // skip non-directories and symlinks - if (!modules_dir_->is_regular_directory()) - continue; - - std::shared_ptr rpath{ - new RelativePath(modules_dir_, modules_dir_->filename())}; - std::shared_ptr f{ - new ModulesDir(rpath)}; - - std::shared_ptr build_path{f->build_path()}; - if (build_path) - module_map[f->filename()].push_back( - BuildDir::try_construct(build_path)); - - // add moduledir after dependant dirs - // otherwise moduledir will be removed first and a later failure - // would make it impossible to find builddir again - module_map[f->filename()].push_back(f); + if (!ignore_module_dir) { + // collect all moduledirs first + modules_dir_.reset(new DirectoryStream(module_path)); + while (modules_dir_->read()) + { + // skip ., .. and all hidden files + if (modules_dir_->filename()[0] == '.') + continue; + // skip non-directories and symlinks + if (!modules_dir_->is_regular_directory()) + continue; + + std::shared_ptr rpath{ + new RelativePath(modules_dir_, modules_dir_->filename())}; + std::shared_ptr f{ + new ModulesDir(rpath)}; + + std::shared_ptr build_path{f->build_path()}; + if (build_path) + module_map[f->filename()].push_back( + BuildDir::try_construct(build_path)); + + // add moduledir after dependant dirs + // otherwise moduledir will be removed first and a later failure + // would make it impossible to find builddir again + module_map[f->filename()].push_back(f); + } } // collect all kernel files from /boot @@ -187,12 +190,14 @@ bool StdLayout::find_kernels() fset.internal_version(internal_ver); // associate the module dir - module_map_type::iterator mi - = module_map.find(internal_ver); - if (mi != module_map.end()) - { - std::copy(mi->second.begin(), mi->second.end(), - std::back_inserter(fset.files())); + if (!ignore_module_dir) { + module_map_type::iterator mi + = module_map.find(internal_ver); + if (mi != module_map.end()) + { + std::copy(mi->second.begin(), mi->second.end(), + std::back_inserter(fset.files())); + } } } // otherwise, check if it matches the previous one @@ -226,20 +231,23 @@ bool StdLayout::find_kernels() // leave only unused moduledirs in modules map // others should have been copied into kernels already - module_map.erase(kf.second.internal_version()); + if(!ignore_module_dir) + module_map.erase(kf.second.internal_version()); // finally, move the FileSet to kernels kernels_.push_back(std::move(kf.second)); } - // add orphaned moduledirs to the final list - for (std::pair>>& km : module_map) - { - FileSet module_set; - module_set.internal_version(km.first); - std::move(km.second.begin(), km.second.end(), - std::back_inserter(module_set.files())); - kernels_.push_back(std::move(module_set)); + if(!ignore_module_dir) { + // add orphaned moduledirs to the final list + for (std::pair>>& km : module_map) + { + FileSet module_set; + module_set.internal_version(km.first); + std::move(km.second.begin(), km.second.end(), + std::back_inserter(module_set.files())); + kernels_.push_back(std::move(module_set)); + } } return true; diff --git a/src/ek2/options.h b/src/ek2/options.h index b7998d3..fe9797f 100644 --- a/src/ek2/options.h +++ b/src/ek2/options.h @@ -17,6 +17,7 @@ struct Options std::string module_path; bool pretend; + bool ignore_module_dir; // newest kernels to keep, 0 to disable removing old int keep_newest; }; diff --git a/src/main.cxx b/src/main.cxx index 73b8d01..7d3913a 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -26,7 +26,7 @@ extern "C" # include }; -static const char* short_options = "ln:o:s:B:M:phV"; +static const char* short_options = "ln:o:s:B:M:phVe"; static const struct option long_options[] = { { "list-kernels", no_argument, nullptr, 'l' }, @@ -42,6 +42,7 @@ static const struct option long_options[] = { { "help", no_argument, nullptr, 'h' }, { "version", no_argument, nullptr, 'V' }, + { "ignore-module-dir", no_argument, nullptr, 'e' }, { nullptr, no_argument, nullptr, 0 }, }; @@ -53,6 +54,7 @@ static void print_help(std::ostream& out, const char* argv0) " -l, --list-kernels list installed kernels\n" "\n" "Removal options:\n" + " -e, --ignore-module-dir don't remove module dir\n" " -n, --keep-newest N keep only N newest kernels\n" " -p, --pretend print the plan but do not do anything\n" "\n" @@ -106,6 +108,7 @@ int sub_main(int argc, char* argv[]) "/lib/modules", // module_path false, // pretend + false, // ignore module dir 0, // keep_newest }; @@ -165,6 +168,9 @@ int sub_main(int argc, char* argv[]) case 'p': opts.pretend = true; break; + case 'e': + opts.ignore_module_dir = true; + break; case 'h': print_help(std::cout, argv[0]);