Created
May 26, 2019 14:36
-
-
Save abrasive/dd85c7bb4686200927df660a2b4f1d93 to your computer and use it in GitHub Desktop.
zfs_test_null.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from portage.util.file_copy import _optimized_copyfile | |
import shutil | |
import sys | |
import os | |
import secrets | |
import random | |
import pathlib | |
if len(sys.argv) != 3: | |
print(f"usage: {sys.argv[0]} scratch_directory dest_directory") | |
print("(cannot be the same directory, as it will create a zfs_test subdir in each)") | |
sys.exit(1) | |
src_dir = pathlib.Path(sys.argv[1]) / 'zfs_test' | |
dst_dir = pathlib.Path(sys.argv[2]) / 'zfs_test' | |
if os.path.isdir(src_dir): | |
shutil.rmtree(src_dir) | |
os.mkdir(src_dir) | |
if os.path.isdir(dst_dir): | |
shutil.rmtree(dst_dir) | |
os.mkdir(dst_dir) | |
files = [] | |
for i in range(1000): | |
fn = 'test%05x' % i | |
data = secrets.token_bytes(random.randint(100, 1000000)) | |
files.append(fn) | |
open(src_dir / fn, 'wb', buffering=False).write(data) | |
for f in files: | |
_optimized_copyfile(src_dir / f, dst_dir / f) | |
bad = False | |
for f in files: | |
data = open(dst_dir / f, 'rb').read() | |
for b in data: | |
if b: | |
break | |
else: | |
print("%s: nulls" % f) | |
bad = True | |
sys.exit(bad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment