|
35 | 35 | import libioc.Config.Jail.File
|
36 | 36 |
|
37 | 37 |
|
| 38 | +class FstabFsSpec(libioc.Types.AbsolutePath): |
| 39 | + """Enforces an AbsolutePath or special device name.""" |
| 40 | + |
| 41 | + PATTERN = re.compile(r"^[A-Za-z][A-Za-z0-9]*$") |
| 42 | + |
| 43 | + def __init__(self, sequence: str) -> None: |
| 44 | + if self.PATTERN.match(sequence) is not None: |
| 45 | + self = str(sequence) # type: ignore |
| 46 | + else: |
| 47 | + super().__init__(sequence) |
| 48 | + |
| 49 | + |
38 | 50 | class FstabLine(dict):
|
39 | 51 | """Model a line of an fstab file."""
|
40 | 52 |
|
@@ -76,20 +88,10 @@ def __setitem__(
|
76 | 88 | value: typing.Union[str, libioc.Types.AbsolutePath]
|
77 | 89 | ) -> None:
|
78 | 90 | """Set an item of the FstabLine."""
|
79 |
| - _type = None |
80 | 91 | if key == "source":
|
81 |
| - _type = libioc.Types.Path |
| 92 | + dict.__setitem__(self, key, FstabFsSpec(value)) |
82 | 93 | elif key == "destination":
|
83 |
| - _type = libioc.Types.AbsolutePath |
84 |
| - |
85 |
| - if _type is not None: # source or destination |
86 |
| - if isinstance(value, str) is True: |
87 |
| - absolute_path = _type(value) |
88 |
| - elif isinstance(value, _type) is True: |
89 |
| - absolute_path = value |
90 |
| - else: |
91 |
| - raise ValueError("String or AbsolutePath expected") |
92 |
| - dict.__setitem__(self, key, absolute_path) |
| 94 | + dict.__setitem__(self, key, libioc.Types.AbsolutePath(value)) |
93 | 95 | elif key in ["type", "options", "dump", "passnum", "comment"]:
|
94 | 96 | dict.__setitem__(self, key, value)
|
95 | 97 | else:
|
|
0 commit comments