Enable long filename configuration and provide read-only DOS compatibility export
This commit is contained in:
23
tests/test_dos_export.py
Normal file
23
tests/test_dos_export.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pathlib import Path
|
||||
import tempfile,subprocess,os,re
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
base=Path(d);src=base/'src';src.mkdir()
|
||||
for name in ['Langer Dateiname mit Umlaut ä.txt','readme.txt','README.TXT','CON','LFNAMES.TXT']:(src/name).write_text(name)
|
||||
(src/'Langer Unterordner').mkdir();(src/'Langer Unterordner'/'Bericht November 2026.pdf').write_bytes(b'pdf')
|
||||
dst=base/'dos';subprocess.run(['python3',str(root/'dos-compat-export.py'),str(src),str(dst)],check=True)
|
||||
originals={f.read_bytes() for f in src.rglob('*') if f.is_file()}
|
||||
copied={f.read_bytes() for f in dst.rglob('*') if f.is_file() and f.name!='LFNAMES.TXT'}
|
||||
assert originals==copied
|
||||
for folder in [dst,*[p for p in dst.rglob('*') if p.is_dir()]]:
|
||||
names=[p.name for p in folder.iterdir()];assert len(names)==len(set(names))
|
||||
assert all(re.fullmatch(r'[A-Z0-9_]{1,8}(\.[A-Z0-9_]{1,3})?',n) for n in names)
|
||||
assert 'CON' not in names
|
||||
assert (folder/'LFNAMES.TXT').exists()
|
||||
assert 'Langer Dateiname mit Umlaut ä.txt' in (dst/'LFNAMES.TXT').read_bytes().decode('cp850')
|
||||
# source links must fail rather than exporting data outside the selected tree
|
||||
(src/'link').symlink_to('/etc/passwd')
|
||||
assert subprocess.run(['python3',str(root/'dos-compat-export.py'),str(src),str(base/'bad')],capture_output=True).returncode!=0
|
||||
for f in dst.rglob('*'):f.chmod(0o755 if f.is_dir() else 0o644)
|
||||
dst.chmod(0o755)
|
||||
print('PASS: DOS aliases, collisions, reserved names, bytes, CP850 catalog, link rejection')
|
||||
Reference in New Issue
Block a user