Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.

Commit b37fc44

Browse files
committed
Add option to disable search of modules
Closes: #12
1 parent 14f1428 commit b37fc44

File tree

3 files changed

+56
-41
lines changed

3 files changed

+56
-41
lines changed

src/ek2/layouts/std.cxx

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,41 @@ bool StdLayout::find_kernels()
100100
{
101101
const std::string& boot_path = opts_.boot_path;
102102
const std::string& module_path = opts_.module_path;
103+
const bool ignore_module_dir = opts_.ignore_module_dir;
103104

104105
std::unordered_map<std::string, FileSet> file_map;
105106
typedef std::unordered_map<std::string,
106107
std::vector<std::shared_ptr<File>>>
107108
module_map_type;
108109
module_map_type module_map;
109110

110-
// collect all moduledirs first
111-
modules_dir_.reset(new DirectoryStream(module_path));
112-
while (modules_dir_->read())
113-
{
114-
// skip ., .. and all hidden files
115-
if (modules_dir_->filename()[0] == '.')
116-
continue;
117-
// skip non-directories and symlinks
118-
if (!modules_dir_->is_regular_directory())
119-
continue;
120-
121-
std::shared_ptr<RelativePath> rpath{
122-
new RelativePath(modules_dir_, modules_dir_->filename())};
123-
std::shared_ptr<ModulesDir> f{
124-
new ModulesDir(rpath)};
125-
126-
std::shared_ptr<RelativePath> build_path{f->build_path()};
127-
if (build_path)
128-
module_map[f->filename()].push_back(
129-
BuildDir::try_construct(build_path));
130-
131-
// add moduledir after dependant dirs
132-
// otherwise moduledir will be removed first and a later failure
133-
// would make it impossible to find builddir again
134-
module_map[f->filename()].push_back(f);
111+
if (!ignore_module_dir) {
112+
// collect all moduledirs first
113+
modules_dir_.reset(new DirectoryStream(module_path));
114+
while (modules_dir_->read())
115+
{
116+
// skip ., .. and all hidden files
117+
if (modules_dir_->filename()[0] == '.')
118+
continue;
119+
// skip non-directories and symlinks
120+
if (!modules_dir_->is_regular_directory())
121+
continue;
122+
123+
std::shared_ptr<RelativePath> rpath{
124+
new RelativePath(modules_dir_, modules_dir_->filename())};
125+
std::shared_ptr<ModulesDir> f{
126+
new ModulesDir(rpath)};
127+
128+
std::shared_ptr<RelativePath> build_path{f->build_path()};
129+
if (build_path)
130+
module_map[f->filename()].push_back(
131+
BuildDir::try_construct(build_path));
132+
133+
// add moduledir after dependant dirs
134+
// otherwise moduledir will be removed first and a later failure
135+
// would make it impossible to find builddir again
136+
module_map[f->filename()].push_back(f);
137+
}
135138
}
136139

137140
// collect all kernel files from /boot
@@ -187,12 +190,14 @@ bool StdLayout::find_kernels()
187190
fset.internal_version(internal_ver);
188191

189192
// associate the module dir
190-
module_map_type::iterator mi
191-
= module_map.find(internal_ver);
192-
if (mi != module_map.end())
193-
{
194-
std::copy(mi->second.begin(), mi->second.end(),
195-
std::back_inserter(fset.files()));
193+
if (!ignore_module_dir) {
194+
module_map_type::iterator mi
195+
= module_map.find(internal_ver);
196+
if (mi != module_map.end())
197+
{
198+
std::copy(mi->second.begin(), mi->second.end(),
199+
std::back_inserter(fset.files()));
200+
}
196201
}
197202
}
198203
// otherwise, check if it matches the previous one
@@ -226,20 +231,23 @@ bool StdLayout::find_kernels()
226231

227232
// leave only unused moduledirs in modules map
228233
// others should have been copied into kernels already
229-
module_map.erase(kf.second.internal_version());
234+
if(!ignore_module_dir)
235+
module_map.erase(kf.second.internal_version());
230236

231237
// finally, move the FileSet to kernels
232238
kernels_.push_back(std::move(kf.second));
233239
}
234240

235-
// add orphaned moduledirs to the final list
236-
for (std::pair<const std::string, std::vector<std::shared_ptr<File>>>& km : module_map)
237-
{
238-
FileSet module_set;
239-
module_set.internal_version(km.first);
240-
std::move(km.second.begin(), km.second.end(),
241-
std::back_inserter(module_set.files()));
242-
kernels_.push_back(std::move(module_set));
241+
if(!ignore_module_dir) {
242+
// add orphaned moduledirs to the final list
243+
for (std::pair<const std::string, std::vector<std::shared_ptr<File>>>& km : module_map)
244+
{
245+
FileSet module_set;
246+
module_set.internal_version(km.first);
247+
std::move(km.second.begin(), km.second.end(),
248+
std::back_inserter(module_set.files()));
249+
kernels_.push_back(std::move(module_set));
250+
}
243251
}
244252

245253
return true;

src/ek2/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Options
1717
std::string module_path;
1818

1919
bool pretend;
20+
bool ignore_module_dir;
2021
// newest kernels to keep, 0 to disable removing old
2122
int keep_newest;
2223
};

src/main.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C"
2626
# include <getopt.h>
2727
};
2828

29-
static const char* short_options = "ln:o:s:B:M:phV";
29+
static const char* short_options = "ln:o:s:B:M:phVe";
3030
static const struct option long_options[] = {
3131
{ "list-kernels", no_argument, nullptr, 'l' },
3232

@@ -42,6 +42,7 @@ static const struct option long_options[] = {
4242

4343
{ "help", no_argument, nullptr, 'h' },
4444
{ "version", no_argument, nullptr, 'V' },
45+
{ "ignore-module-dir", no_argument, nullptr, 'e' },
4546

4647
{ nullptr, no_argument, nullptr, 0 },
4748
};
@@ -53,6 +54,7 @@ static void print_help(std::ostream& out, const char* argv0)
5354
" -l, --list-kernels list installed kernels\n"
5455
"\n"
5556
"Removal options:\n"
57+
" -e, --ignore-module-dir don't remove module dir\n"
5658
" -n, --keep-newest N keep only N newest kernels\n"
5759
" -p, --pretend print the plan but do not do anything\n"
5860
"\n"
@@ -106,6 +108,7 @@ int sub_main(int argc, char* argv[])
106108
"/lib/modules", // module_path
107109

108110
false, // pretend
111+
false, // ignore module dir
109112
0, // keep_newest
110113
};
111114

@@ -165,6 +168,9 @@ int sub_main(int argc, char* argv[])
165168
case 'p':
166169
opts.pretend = true;
167170
break;
171+
case 'e':
172+
opts.ignore_module_dir = true;
173+
break;
168174

169175
case 'h':
170176
print_help(std::cout, argv[0]);

0 commit comments

Comments
 (0)