PDTCRYPT_VERBOSE = False
PDTCRYPT_STRICTIVS = False
+PDTCRYPT_OVERWRITE = False
PDTCRYPT_BLOCKSIZE = 1 << 12
PDTCRYPT_SINK = 0
PDTCRYPT_SOURCE = 1
assert total_obj > 0
fname = PDTCRYPT_SPLITNAME % total_obj
try:
- outfd = os.open (fname, os.O_CREAT | os.O_EXCL | os.O_WRONLY,
- 0o600, dir_fd=outs)
+ oflags = os.O_CREAT | os.O_WRONLY
+ if PDTCRYPT_OVERWRITE is True:
+ oflags |= os.O_TRUNC
+ else:
+ oflags |= os.O_EXCL
+ outfd = os.open (fname, oflags, 0o600, dir_fd=outs)
if PDTCRYPT_VERBOSE is True:
noise ("PDT: new output file %s → %d" % (fname, outfd))
except FileExistsError as exn:
elif arg in [ "-o", "--out", "--dest", "--sink" ]:
outsspec = next (argvi)
if PDTCRYPT_VERBOSE is True: noise ("PDT: decrypt to %s" % outsspec)
+ elif arg in [ "-f", "--force" ]:
+ global PDTCRYPT_OVERWRITE
+ PDTCRYPT_OVERWRITE = True
+ if PDTCRYPT_VERBOSE is True: noise ("PDT: overwrite existing files")
elif arg in [ "-S", "--split" ]:
mode |= PDTCRYPT_SPLIT
if PDTCRYPT_VERBOSE is True: noise ("PDT: split files")
def test_cli_multiple_files_decrypt(self):
"""
Create a tar file with multiple files inside, using concat
- compression and encryption mode. Then decrypt with ``crypto.py``,
- decompress it with zcat and untar it with gnu tar.
+ compression and encryption mode. Then decrypt and split with
+ ``crypto.py``, decompress it with zcat and untar it with gnu tar.
"""
# create sample data
os.unlink(k)
assert os.path.exists("sample.tar.gz.pdtcrypt")
- ret = os.system("python3 -s ./deltatar/crypto.py key <sample.tar.gz.pdtcrypt >sample.tar.gz")
+ ret = os.system("python3 -s ./deltatar/crypto.py key --split "
+ "-i sample.tar.gz.pdtcrypt -o .")
assert ret == 0
- assert os.path.exists("sample.tar.gz")
- os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
- os.system("tar xf sample.tar")
+ for i in range (len (hash)):
+ fname = "pdtcrypt-object-%d.bin" % (i + 1)
+ assert os.path.exists(fname)
+ os.system("zcat '%s' 2>/dev/null > sample.tar" % fname)
+ os.system("tar xf sample.tar")
for key, value in hash.items():
assert os.path.exists(key)