mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-30 04:54:04 +08:00
test(e2e): make tgz fixture gzip header deterministic
This commit is contained in:
@@ -38,22 +38,36 @@ const ensureArchive = (name, generator) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildDeterministicTar = (out, gzip = false) => {
|
const buildDeterministicTar = (out, gzip = false) => {
|
||||||
const py = String.raw`import io, tarfile
|
const py = String.raw`import io, tarfile, gzip
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
out = Path(r'''${out}''')
|
out = Path(r'''${out}''')
|
||||||
inner_path = Path(r'''${innerFile}''')
|
inner_path = Path(r'''${innerFile}''')
|
||||||
data = inner_path.read_bytes()
|
data = inner_path.read_bytes()
|
||||||
mode = 'w:gz' if ${gzip ? 'True' : 'False'} else 'w'
|
use_gzip = ${gzip ? 'True' : 'False'}
|
||||||
with tarfile.open(out, mode=mode, format=tarfile.USTAR_FORMAT) as tf:
|
|
||||||
info = tarfile.TarInfo('inner.txt')
|
if use_gzip:
|
||||||
info.size = len(data)
|
with out.open('wb') as f:
|
||||||
info.mtime = 946684800 # 2000-01-01 00:00:00 UTC
|
with gzip.GzipFile(filename='', mode='wb', fileobj=f, mtime=0) as gz:
|
||||||
info.uid = 0
|
with tarfile.open(fileobj=gz, mode='w', format=tarfile.USTAR_FORMAT) as tf:
|
||||||
info.gid = 0
|
info = tarfile.TarInfo('inner.txt')
|
||||||
info.uname = 'root'
|
info.size = len(data)
|
||||||
info.gname = 'root'
|
info.mtime = 946684800 # 2000-01-01 00:00:00 UTC
|
||||||
tf.addfile(info, io.BytesIO(data))
|
info.uid = 0
|
||||||
|
info.gid = 0
|
||||||
|
info.uname = 'root'
|
||||||
|
info.gname = 'root'
|
||||||
|
tf.addfile(info, io.BytesIO(data))
|
||||||
|
else:
|
||||||
|
with tarfile.open(out, mode='w', format=tarfile.USTAR_FORMAT) as tf:
|
||||||
|
info = tarfile.TarInfo('inner.txt')
|
||||||
|
info.size = len(data)
|
||||||
|
info.mtime = 946684800 # 2000-01-01 00:00:00 UTC
|
||||||
|
info.uid = 0
|
||||||
|
info.gid = 0
|
||||||
|
info.uname = 'root'
|
||||||
|
info.gname = 'root'
|
||||||
|
tf.addfile(info, io.BytesIO(data))
|
||||||
`;
|
`;
|
||||||
execFileSync('python3', ['-c', py]);
|
execFileSync('python3', ['-c', py]);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user