Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions src/ek2/layouts/std.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,41 @@ 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<std::string, FileSet> file_map;
typedef std::unordered_map<std::string,
std::vector<std::shared_ptr<File>>>
module_map_type;
module_map_type module_map;

// 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<RelativePath> rpath{
new RelativePath(modules_dir_, modules_dir_->filename())};
std::shared_ptr<ModulesDir> f{
new ModulesDir(rpath)};

std::shared_ptr<RelativePath> 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<RelativePath> rpath{
new RelativePath(modules_dir_, modules_dir_->filename())};
std::shared_ptr<ModulesDir> f{
new ModulesDir(rpath)};

std::shared_ptr<RelativePath> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<const std::string, std::vector<std::shared_ptr<File>>>& 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<const std::string, std::vector<std::shared_ptr<File>>>& 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;
Expand Down
1 change: 1 addition & 0 deletions src/ek2/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
8 changes: 7 additions & 1 deletion src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C"
# include <getopt.h>
};

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' },

Expand All @@ -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 },
};
Expand All @@ -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"
Expand Down Expand Up @@ -106,6 +108,7 @@ int sub_main(int argc, char* argv[])
"/lib/modules", // module_path

false, // pretend
false, // ignore module dir
0, // keep_newest
};

Expand Down Expand Up @@ -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]);
Expand Down