avoid shredding empty files, also x/0
also cleaned up unused import and exception var
This commit is contained in:
parent
627dec716b
commit
f26adcc7da
1 changed files with 17 additions and 15 deletions
|
@ -71,7 +71,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ansible.compat.six import PY3, byte2int
|
from ansible.compat.six import PY3
|
||||||
from ansible.utils.unicode import to_unicode, to_bytes
|
from ansible.utils.unicode import to_unicode, to_bytes
|
||||||
|
|
||||||
HAS_ANY_PBKDF2HMAC = HAS_PBKDF2 or HAS_PBKDF2HMAC
|
HAS_ANY_PBKDF2HMAC = HAS_PBKDF2 or HAS_PBKDF2HMAC
|
||||||
|
@ -236,6 +236,8 @@ class VaultEditor:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
file_len = os.path.getsize(tmp_path)
|
file_len = os.path.getsize(tmp_path)
|
||||||
|
|
||||||
|
if file_len > 0: # avoid work when file was empty
|
||||||
max_chunk_len = min(1024*1024*2, file_len)
|
max_chunk_len = min(1024*1024*2, file_len)
|
||||||
|
|
||||||
passes = 3
|
passes = 3
|
||||||
|
@ -273,7 +275,7 @@ class VaultEditor:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = call(['shred', tmp_path])
|
r = call(['shred', tmp_path])
|
||||||
except OSError as e:
|
except OSError:
|
||||||
# shred is not available on this system, or some other error occured.
|
# shred is not available on this system, or some other error occured.
|
||||||
r = 1
|
r = 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue