-
Notifications
You must be signed in to change notification settings - Fork 19
Fix gpg command hanging #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,15 +28,30 @@ def unpack(self, password: str = None, duplicates=None): | |
| # ToDo | ||
| # locked system call occurred during sandboxing!\nip=0x7f9d2bc0fa97 sp=0x7ffdcb8d5eb8 abi=0 nr=102 syscall=getuid | ||
| # ret = self.zipjail(filepath, dirpath, "-o", os.path.join(dirpath, "extracted"), "--passphrase=%s" % (password or ""), filepath) | ||
| p = subprocess.Popen( | ||
| (self.exe, "--decrypt", "--batch", "-o", os.path.join(dirpath, "extracted"), "--passphrase=%s" % (password or ""), filepath), | ||
| stdin=subprocess.PIPE, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| ) | ||
|
|
||
| return_code = p.wait() | ||
| _, _ = p.communicate() | ||
| p = None | ||
| try: | ||
| p = subprocess.Popen( | ||
| (self.exe, "--decrypt", "--batch", "-o", os.path.join(dirpath, "extracted"), | ||
| "--passphrase=%s" % (password or ""), filepath), | ||
| stdin=subprocess.DEVNULL, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| ) | ||
|
|
||
| stdout, stderr = p.communicate(timeout=30) | ||
| return_code = p.returncode | ||
|
|
||
| except subprocess.TimeoutExpired: | ||
| if p: | ||
| p.kill() | ||
| _, _ = p.communicate() | ||
| return_code = 1 | ||
| except Exception: | ||
| if p: | ||
| p.kill() | ||
| p.wait() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better not to call communicate() in a generic except block. If the error was caused by the pipe itself being broken (e.g., BrokenPipeError or OSError), calling communicate() might raise another exception. |
||
| return_code = 1 | ||
|
|
||
| ret = not return_code | ||
| if not ret: | ||
| return [] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
stdoutandstderrvariables are captured fromp.communicate()but are not used later in the function. To make it clear that they are intentionally ignored, it's conventional to name them with an underscore (_).