Skip to content

Commit 85ce7ad

Browse files
authored
NAS-101668 / 11.3 / Split on both spaces and tabs for fstab (iocage#929)
* Split on both spaces and tabs for fstab Previous behavior erroneously expected iocage to be the sole consumer of the fstab. - This now will skip comments, and split on spaces/tabs as it should have before. - Move reading fstab to fstab_list() method iocage side of truenas/middleware#3041 Signed-off-by: Brandon Schneider <[email protected]> * Doctrees/Docset updates Signed-off-by: Brandon Schneider <[email protected]> * We should also not show empty lines Signed-off-by: Brandon Schneider <[email protected]>
1 parent 207e0a6 commit 85ce7ad

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

doc/build/doctrees/environment.pickle

70 Bytes
Binary file not shown.

doc/build/html/searchindex.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iocage.docset/Contents/Resources/Documents/iocage_lib.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
585585
<p>Manipulate a jails fstab</p>
586586
<dl class="class">
587587
<dt id="iocage_lib.ioc_fstab.IOCFstab"><a name="//apple_ref/cpp/Class/iocage_lib.ioc_fstab.IOCFstab"></a>
588-
<em class="property">class </em><code class="descclassname">iocage_lib.ioc_fstab.</code><code class="descname">IOCFstab</code><span class="sig-paren">(</span><em>uuid</em>, <em>action</em>, <em>source=''</em>, <em>destination=''</em>, <em>fstype=''</em>, <em>fsoptions=''</em>, <em>fsdump=''</em>, <em>fspass=''</em>, <em>index=None</em>, <em>silent=False</em>, <em>callback=None</em>, <em>header=False</em>, <em>_fstab_list=None</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_fstab.IOCFstab" title="Permalink to this definition"></a></dt>
588+
<em class="property">class </em><code class="descclassname">iocage_lib.ioc_fstab.</code><code class="descname">IOCFstab</code><span class="sig-paren">(</span><em>uuid</em>, <em>action</em>, <em>source=''</em>, <em>destination=''</em>, <em>fstype=''</em>, <em>fsoptions=''</em>, <em>fsdump=''</em>, <em>fspass=''</em>, <em>index=None</em>, <em>silent=False</em>, <em>callback=None</em>, <em>header=False</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_fstab.IOCFstab" title="Permalink to this definition"></a></dt>
589589
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
590590
<p>Will add or remove an entry, and mount or umount the filesystem.</p>
591591
<dl class="method">
@@ -933,18 +933,18 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
933933
<p>iocage plugin module</p>
934934
<dl class="class">
935935
<dt id="iocage_lib.ioc_plugin.IOCPlugin"><a name="//apple_ref/cpp/Class/iocage_lib.ioc_plugin.IOCPlugin"></a>
936-
<em class="property">class </em><code class="descclassname">iocage_lib.ioc_plugin.</code><code class="descname">IOCPlugin</code><span class="sig-paren">(</span><em>release=None</em>, <em>plugin=None</em>, <em>branch=None</em>, <em>keep_jail_on_failure=False</em>, <em>callback=None</em>, <em>silent=False</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin" title="Permalink to this definition"></a></dt>
936+
<em class="property">class </em><code class="descclassname">iocage_lib.ioc_plugin.</code><code class="descname">IOCPlugin</code><span class="sig-paren">(</span><em>release=None</em>, <em>jail=None</em>, <em>plugin=None</em>, <em>branch=None</em>, <em>keep_jail_on_failure=False</em>, <em>callback=None</em>, <em>silent=False</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin" title="Permalink to this definition"></a></dt>
937937
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
938938
<p>This is responsible for the general life cycle of a plugin jail. This
939939
includes creation, updating and upgrading.</p>
940940
<dl class="method">
941941
<dt id="iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin"><a name="//apple_ref/cpp/Method/iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin"></a>
942-
<code class="descname">fetch_plugin</code><span class="sig-paren">(</span><em>_json</em>, <em>props</em>, <em>num</em>, <em>accept_license</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin" title="Permalink to this definition"></a></dt>
942+
<code class="descname">fetch_plugin</code><span class="sig-paren">(</span><em>props</em>, <em>num</em>, <em>accept_license</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin" title="Permalink to this definition"></a></dt>
943943
<dd><p>Helper to fetch plugins</p>
944944
</dd></dl>
945945
<dl class="method">
946946
<dt id="iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin_index"><a name="//apple_ref/cpp/Method/iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin_index"></a>
947-
<code class="descname">fetch_plugin_index</code><span class="sig-paren">(</span><em>props</em>, <em>_list=False</em>, <em>list_header=False</em>, <em>list_long=False</em>, <em>accept_license=False</em>, <em>icon=False</em>, <em>official=False</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin_index" title="Permalink to this definition"></a></dt>
947+
<code class="descname">fetch_plugin_index</code><span class="sig-paren">(</span><em>props</em>, <em>_list=False</em>, <em>list_header=False</em>, <em>list_long=False</em>, <em>accept_license=False</em>, <em>icon=False</em>, <em>official=False</em>, <em>index_only=False</em><span class="sig-paren">)</span><a class="headerlink" href="#iocage_lib.ioc_plugin.IOCPlugin.fetch_plugin_index" title="Permalink to this definition"></a></dt>
948948
<dd></dd></dl>
949949
<dl class="method">
950950
<dt id="iocage_lib.ioc_plugin.IOCPlugin.update"><a name="//apple_ref/cpp/Method/iocage_lib.ioc_plugin.IOCPlugin.update"></a>

iocage.docset/Contents/Resources/Documents/searchindex.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iocage_lib/ioc_fstab.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class IOCFstab(object):
4444

4545
def __init__(self, uuid, action, source='', destination='', fstype='',
4646
fsoptions='', fsdump='', fspass='', index=None, silent=False,
47-
callback=None, header=False, _fstab_list=None
47+
callback=None, header=False
4848
):
4949
self.pool = iocage_lib.ioc_json.IOCJson().json_get_value("pool")
5050
self.iocroot = iocage_lib.ioc_json.IOCJson(
@@ -69,16 +69,14 @@ def __init__(self, uuid, action, source='', destination='', fstype='',
6969

7070
self.mount = f'{self.src}\t{self.dest}\t{self.fstype}\t' \
7171
f'{self.fsoptions}\t{self.fsdump}\t{self.fspass}'
72-
self._fstab_list = _fstab_list
7372
self.header = header
7473
self.silent = silent
7574
self.callback = callback
7675

77-
if action != 'list':
78-
self.fstab = list(self.__read_fstab__())
76+
self.fstab = list(self.__read_fstab__())
7977

80-
if action != 'edit':
81-
self.dests = self.__validate_fstab__(self.fstab, 'all')
78+
if action != 'edit' and action != 'list':
79+
self.dests = self.__validate_fstab__(self.fstab, 'all')
8280

8381
self.__fstab_parse__()
8482

@@ -128,21 +126,33 @@ def __fstab_parse__(self):
128126

129127
def __read_fstab__(self):
130128
with open(f"{self.iocroot}/jails/{self.uuid}/fstab", "r") as f:
131-
for line in f:
132-
yield line.rstrip()
129+
for i, line in enumerate(f, ):
130+
if not line.strip():
131+
continue
132+
133+
if not line.strip().startswith('#'):
134+
if self.action != 'list':
135+
yield line.rstrip()
136+
else:
137+
line = line.rsplit('#')[0].rstrip()
138+
yield ([i, line])
133139

134140
def __validate_fstab__(self, fstab, mode='single'):
135141
dests = {}
136142
verrors = []
137143
jail_root = f'{self.iocroot}/jails/{self.uuid}/root'
138144

139145
for index, line in enumerate(fstab):
146+
# Comment
147+
if line.strip().startswith('#'):
148+
continue
140149
mnt = line.split(' # ')[0]
141150

142151
try:
143152
source, destination, fstype, options, \
144-
dump, _pass = line.split('\t')[0:6]
153+
dump, _pass = line.split()[0:6]
145154
_pass = _pass.split()[0] # iocage comment can interfere
155+
146156
except ValueError:
147157
verrors.append(
148158
f'Malformed fstab at line {index}: {repr(line)}'
@@ -315,7 +325,7 @@ def __fstab_remove__(self):
315325
if line.rsplit('#')[0].rstrip() == self.mount \
316326
or index == self.index:
317327
removed = True
318-
dest = line.split('\t')[1]
328+
dest = line.split()[1]
319329

320330
continue
321331

@@ -441,7 +451,7 @@ def fstab_list(self):
441451
flat_fstab = [
442452
(
443453
i, self.__fstab_decode__(f)
444-
) for (i, f) in self._fstab_list
454+
) for (i, f) in self.fstab
445455
]
446456

447457
if not self.header:

iocage_lib/iocage.py

-10
Original file line numberDiff line numberDiff line change
@@ -1171,15 +1171,6 @@ def fstab(self,
11711171
},
11721172
_callback=self.callback,
11731173
silent=self.silent)
1174-
else:
1175-
_fstab_list = []
1176-
index = 0
1177-
1178-
with open(f"{self.iocroot}/jails/{uuid}/fstab", "r") as _fstab:
1179-
for line in _fstab.readlines():
1180-
line = line.rsplit("#")[0].rstrip()
1181-
_fstab_list.append([index, line])
1182-
index += 1
11831174

11841175
if action == "list":
11851176
fstab = ioc_fstab.IOCFstab(
@@ -1193,7 +1184,6 @@ def fstab(self,
11931184
_pass,
11941185
index=index,
11951186
header=header,
1196-
_fstab_list=_fstab_list
11971187
).fstab_list()
11981188

11991189
return fstab

0 commit comments

Comments
 (0)