Skip to content

Commit 81da21e

Browse files
committed
fixed masking behavior, root subvol selection
Signed-off-by: Zen <[email protected]>
1 parent ad3477c commit 81da21e

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

ugrd/base/core.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '1.2.4'
2+
__version__ = '1.3.0'
33

44
from pathlib import Path
55
from typing import Union
@@ -279,3 +279,38 @@ def _process_file_owner(self, owner: Union[str, int]) -> None:
279279
self.logger.error("Unable to process file owner: %s" % owner)
280280
raise ValueError("Invalid type passed for file owner: %s" % type(owner))
281281

282+
283+
def _process_masks_multi(self, runlevel: str, function: str) -> None:
284+
"""
285+
Processes a mask.
286+
"""
287+
self.logger.debug("[%s] Adding mask: %s" % (runlevel, function))
288+
self['masks'][runlevel] = function
289+
290+
if runlevel not in self['imports']:
291+
self.logger.warning("[%s] Runlevel not found in imports, skipping deletion: %s" % (runlevel, function))
292+
else:
293+
for func in self['imports'][runlevel]:
294+
if func.__name__ == function:
295+
self['imports'][runlevel].remove(func)
296+
self.logger.info("[%s] Removing function from runlevel: %s" % (runlevel, function))
297+
break
298+
else:
299+
self.logger.warning("[%s] Function not found in runlevel, skipping deletion: %s" % (runlevel, function))
300+
301+
302+
303+
304+
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+

ugrd/base/core.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ minor = 1
2121
"_process_file_owner",
2222
"_process_nodes_multi",
2323
"_process_paths_multi",
24+
"_process_masks_multi",
2425
]
2526

2627
[imports.build_pre]
@@ -40,6 +41,7 @@ symlinks = "dict" # Add the symlinks property, used to define the symlinks to b
4041
copies = "dict" # Add the copies property, used to define the files to be copied to the initramfs
4142
nodes = "dict" # Add the nodes property, used to define the device nodes to be created
4243
paths = "NoDupFlatList" # Paths to be copied to the initramfs
44+
masks = "dict" # Imports to be masked in the initramfs
4345
build_dir = "Path" # The directory where the initramfs is built
4446
out_dir = "Path" # The directory where the initramfs is packed/output. If no packer is used, this is the final output directory.
4547
old_count = "int" # The number of times to cycle old files before deleting

ugrd/fs/btrfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def set_root_subvol(self) -> str:
7979
sets $root_subvol
8080
"""
8181
if root_subvol := self.config_dict.get("root_subvol"):
82+
self.config_dict['masks'] = {'init_mount': 'mount_root'}
8283
return f"export root_subvol={root_subvol}"
8384
elif self.config_dict.get('subvol_selector'):
8485
base_mount_path = self.config_dict['base_mount_path']

ugrd/initramfs_dict.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class InitramfsConfigDict(dict):
2525
builtin_parameters = {'mod_depends': NoDupFlatList, # Modules required by other modules, will be re-checked calling .verify_deps()
2626
'modules': NoDupFlatList, # A list of the names of modules which have been loaded, mostly used for dependency checking
2727
'imports': dict, # A dict of functions to be imported into the initramfs, under their respective hooks
28-
'mask': dict, # A dict of imported functions to be masked
2928
'custom_parameters': dict, # Custom parameters loaded from imports
3029
'custom_processing': dict, # Custom processing functions which will be run to validate and process parameters
3130
'_processing': dict} # A dict of queues containing parameters which have been set before the type was known
@@ -221,12 +220,14 @@ def verify_mask(self) -> None:
221220
"""
222221
Processes masked imports
223222
"""
224-
for mask_hook, mask_items in self['mask'].items():
225-
if self['imports'].get(mask_hook):
226-
for function in self['imports'][mask_hook]:
223+
for mask_hook, mask_items in self['masks'].items():
224+
if runlevel := self['imports'].get(mask_hook):
225+
for function in runlevel.copy():
227226
if function.__name__ in mask_items:
228-
self.logger.warning("Masking import: %s" % function.__name__)
229-
self['imports'][mask_hook].remove(function)
227+
runlevel.remove(function)
228+
self.logger.warning("[%s] Masking import: %s" % (mask_hook, function.__name__))
229+
else:
230+
self.logger.debug("[%s] Import not found: %s" % (mask_hook, function.__name__))
230231

231232
def __str__(self) -> str:
232233
return pretty_print(self)

0 commit comments

Comments
 (0)