diff --git a/pycryptomator/__init__.py b/pycryptomator/__init__.py index c0e58bb..572e0ac 100644 --- a/pycryptomator/__init__.py +++ b/pycryptomator/__init__.py @@ -1,3 +1,3 @@ COPYRIGHT = '''Copyright (C)2024, by maxpat78.''' -__version__ = '1.1' +__version__ = '1.2' __all__ = ["Vault", "init_vault", "backupDirIds"] diff --git a/pycryptomator/cmshell.py b/pycryptomator/cmshell.py index 4ee8b28..9133ac2 100644 --- a/pycryptomator/cmshell.py +++ b/pycryptomator/cmshell.py @@ -3,7 +3,7 @@ from .cryptomator import * if os.name == 'nt': - from w32lex import split # shlex ban \ in pathnames! + from .w32lex import split # shlex ban \ in pathnames! else: from shlex import split @@ -62,16 +62,18 @@ def do_decrypt(p, arg): print(sys.exception()) def do_encrypt(p, arg): - 'Encrypt files or directories into the vault' + 'Encrypt files or directories into the vault, eventually moving them' argl = split(arg) + move = '-m' in argl + if move: argl.remove('-m') if not argl or argl[0] == '-h' or len(argl) != 2: - print('use: encrypt ') + print('use: encrypt [-m] ') return try: if isdir(argl[0]): - p.vault.encryptDir(argl[0], argl[1]) + p.vault.encryptDir(argl[0], argl[1], move=move) else: - p.vault.encryptFile(argl[0], argl[1]) + p.vault.encryptFile(argl[0], argl[1], move=move) except: print(sys.exception()) diff --git a/pycryptomator/cryptomator.py b/pycryptomator/cryptomator.py index cd1af08..5f1a02b 100644 --- a/pycryptomator/cryptomator.py +++ b/pycryptomator/cryptomator.py @@ -265,7 +265,7 @@ def _encryptf(K, src, dst): dst.write(tag) n += 1 - def encryptFile(p, src, virtualpath, force=False): + def encryptFile(p, src, virtualpath, force=False, move=False): "Encrypt a 'src' file into a pre-existant vault's virtual directory (or a file-like object into a real path)" if hasattr(src, 'read'): # if it's file f = src @@ -285,9 +285,11 @@ def encryptFile(p, src, virtualpath, force=False): if not hasattr(src, 'read'): st = os.stat(src) os.utime(out.name, (st.st_atime, st.st_mtime)) + if move: + os.remove(src) return cb - def encryptDir(p, src, virtualpath, force=False): + def encryptDir(p, src, virtualpath, force=False, move=False): if (virtualpath[0] != '/'): raise BaseException('the vault path must be absolute!') real = p.mkdir(virtualpath) @@ -302,8 +304,11 @@ def encryptDir(p, src, virtualpath, force=False): dn = join(virtualpath, fn[len(src)+1:]) # target pathname p.mkdir(dirname(dn)) print(dn) - total_bytes += p.encryptFile(fn, dn, force) + total_bytes += p.encryptFile(fn, dn, force, move) n += 1 + if move: + print('moved', src) + shutil.rmtree(src) T1 = time.time() print('encrypting %s bytes in %d files and %d directories took %d seconds' % (_fmt_size(total_bytes), n, nn, T1-T0))