summaryrefslogtreecommitdiff
path: root/obnamlib/encryption.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-06-26 21:49:40 +0100
committerLars Wirzenius <liw@liw.fi>2011-06-26 21:49:40 +0100
commitad043d5fa3a04f16e686d83a72a1eac546a9b6ee (patch)
tree634292a132a03dac7b939ad8736242a31c010b0b /obnamlib/encryption.py
parentb254f7b232147444f3c4b3699ff81b603824327d (diff)
downloadobnam-ad043d5fa3a04f16e686d83a72a1eac546a9b6ee.tar.gz
Avoid temporary file for piping data through gpg.
Turns out Python's subprocess.Popen.communicate can handle arbitrarily large amounts of data without blocking. Neat.
Diffstat (limited to 'obnamlib/encryption.py')
-rw-r--r--obnamlib/encryption.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/obnamlib/encryption.py b/obnamlib/encryption.py
index 584cc688..d8fe836a 100644
--- a/obnamlib/encryption.py
+++ b/obnamlib/encryption.py
@@ -75,23 +75,14 @@ def _gpg_pipe(args, data, passphrase):
os.write(keypipe[1], passphrase + '\n')
os.close(keypipe[1])
- # Write the data to temporary file. Remove its name at once, so that
- # if we crash, it gets removed automatically by the kernel.
-
- datafd, dataname = tempfile.mkstemp()
- os.remove(dataname)
- os.write(datafd, data)
- os.lseek(datafd, 0, 0)
-
# Actually run gpg.
argv = ['gpg', '--passphrase-fd', str(keypipe[0]), '-q', '--batch'] + args
- p = subprocess.Popen(argv, stdin=datafd, stdout=subprocess.PIPE,
+ p = subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- out, err = p.communicate()
+ out, err = p.communicate(data)
os.close(keypipe[0])
- os.close(datafd)
# Return output data, or deal with errors.
if p.returncode: # pragma: no cover