Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Arusekk committed Apr 20, 2022
1 parent 0b6f7af commit 09f6756
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import shutil
import six
import socket
import stat
import string
import subprocess
import sys
import tempfile
import threading
Expand Down Expand Up @@ -339,7 +337,7 @@ class ContextType(object):
# Setting any properties on a ContextType object will throw an
# exception.
#
__slots__ = ('_tls', )
__slots__ = '_tls',

#: Default values for :class:`pwnlib.context.ContextType`
defaults = {
Expand Down Expand Up @@ -1289,7 +1287,7 @@ def cache_dir_base(self, new_base):

if new_base != self.cache_dir_base:
del self._tls["cache_dir"]
if os.access(new_base, os.F_OK) and not os.access(new_base, W_OK):
if os.access(new_base, os.F_OK) and not os.access(new_base, os.W_OK):
raise OSError(errno.EPERM, "Cache base dir is not writable")
return new_base

Expand All @@ -1306,6 +1304,7 @@ def cache_dir(self):
>>> cache_dir is not None
True
>>> os.chmod(cache_dir, 0o000)
>>> del context._tls['cache_dir']
>>> context.cache_dir is None
True
>>> os.chmod(cache_dir, 0o755)
Expand Down Expand Up @@ -1333,7 +1332,7 @@ def cache_dir(self):
if exc.errno != errno.EEXIST:
try:
cache_dirpath = tempfile.mkdtemp(prefix=".pwntools-tmp")
except IOError as exc:
except IOError:
# This implies no good candidates for temporary files so we
# have to return `None`
return None
Expand All @@ -1353,6 +1352,12 @@ def cache_dir(self):
else:
return None

@cache_dir.setter
def cache_dir(self, v):
if os.access(v, os.W_OK):
# Stash this in TLS for later reuse
self._tls["cache_dir"] = v

@_validator
def delete_corefiles(self, v):
"""Whether pwntools automatically deletes corefiles after exiting.
Expand Down

0 comments on commit 09f6756

Please sign in to comment.