Fix NFS parser showing /etc/exports example comments as disabled exports

The default nfs-kernel-server package ships /etc/exports with commented
example lines like '# /srv/homes hostname1(rw,...)'. The old parser
treated any comment containing a path as a disabled export, so these
examples showed up in the UI.

Fix: use a distinct '## ' prefix (double-hash + space) for exports that
MicroNAS disables. The parser now only recognises '## /path ...' as a
disabled export — any other '#' line is left as a plain comment.
_write_exports updated to use the same prefix when toggling off.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marcandClaude Sonnet 4.6 committed 2026-06-19 23:52:11 +02:00
1 parent 96055e6375
commit d7892fa7c5
1 file changed
+11 -6
+11 -6
View File
@@ -142,8 +142,13 @@ def add_smb_share(name, path, valid_users):
# ===== NFS ===== # ===== NFS =====
_DISABLED_PREFIX = '## ' # marker MicroNAS uses for disabled exports
def _parse_exports(): def _parse_exports():
"""Parse /etc/exports preserving blanks, comments, and disabled (commented-out) exports.""" """Parse /etc/exports. Only lines starting with '## /' are treated as
disabled exports — everything else that starts with '#' is a plain comment
and is left untouched."""
entries = [] entries = []
try: try:
with open('/etc/exports', 'r') as f: with open('/etc/exports', 'r') as f:
@@ -152,13 +157,13 @@ def _parse_exports():
if not stripped: if not stripped:
entries.append({'kind': 'blank', 'raw': raw}) entries.append({'kind': 'blank', 'raw': raw})
continue continue
if stripped.startswith('#'): if stripped.startswith(_DISABLED_PREFIX + '/'):
inner = stripped[1:].strip() inner = stripped[len(_DISABLED_PREFIX):]
if inner.startswith('/'):
parts = inner.split(None, 1) parts = inner.split(None, 1)
entries.append({'kind': 'export', 'enabled': False, entries.append({'kind': 'export', 'enabled': False,
'path': parts[0], 'rest': parts[1] if len(parts) > 1 else ''}) 'path': parts[0], 'rest': parts[1] if len(parts) > 1 else ''})
else: continue
if stripped.startswith('#'):
entries.append({'kind': 'comment', 'raw': raw}) entries.append({'kind': 'comment', 'raw': raw})
continue continue
parts = stripped.split(None, 1) parts = stripped.split(None, 1)
@@ -173,7 +178,7 @@ def _write_exports(entries):
with open('/etc/exports', 'w') as f: with open('/etc/exports', 'w') as f:
for e in entries: for e in entries:
if e['kind'] == 'export': if e['kind'] == 'export':
prefix = '' if e['enabled'] else '#' prefix = '' if e['enabled'] else _DISABLED_PREFIX
rest = f'\t{e["rest"]}' if e['rest'] else '' rest = f'\t{e["rest"]}' if e['rest'] else ''
f.write(f'{prefix}{e["path"]}{rest}\n') f.write(f'{prefix}{e["path"]}{rest}\n')
else: else: