Skip to content
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

Remove some dead code #1954

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/buildstream/_cas/cascache.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def __init__(self, path, *, casd, remote_cache=False):
os.makedirs(self.tmpdir, exist_ok=True)

self._cache_usage_monitor = None
self._cache_usage_monitor_forbidden = False

self._remote_cache = remote_cache

Expand Down Expand Up @@ -703,7 +702,6 @@ def _send_directory(self, remote, digest):
# (CASCacheUsage): The current status
#
def get_cache_usage(self):
assert not self._cache_usage_monitor_forbidden
return self._cache_usage_monitor.get_cache_usage()

# get_casd()
Expand Down
99 changes: 0 additions & 99 deletions src/buildstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,37 +1130,6 @@ def _set_deterministic_user(directory):
os.chown(os.path.join(root, dirname), user, group, follow_symlinks=False)


# _set_deterministic_mtime()
#
# Set the mtime for every file in a directory tree to the same.
#
# Args:
# directory (str): The directory to recursively set the mtime on
#
def _set_deterministic_mtime(directory):
for dirname, _, filenames in os.walk(directory.encode("utf-8"), topdown=False):
for filename in filenames:
pathname = os.path.join(dirname, filename)

# Python's os.utime only ever modifies the timestamp
# of the target, it is not acceptable to set the timestamp
# of the target here, if we are staging the link target we
# will also set its timestamp.
#
# We should however find a way to modify the actual link's
# timestamp, this outdated python bug report claims that
# it is impossible:
#
# http://bugs.python.org/issue623782
#
# However, nowadays it is possible at least on gnuish systems
# with with the lutimes glibc function.
if not os.path.islink(pathname):
os.utime(pathname, (BST_ARBITRARY_TIMESTAMP, BST_ARBITRARY_TIMESTAMP))

os.utime(dirname, (BST_ARBITRARY_TIMESTAMP, BST_ARBITRARY_TIMESTAMP))


# _tempdir()
#
# A context manager for doing work in a temporary directory.
Expand Down Expand Up @@ -1242,66 +1211,6 @@ def close_tempfile():
yield temp


# _tempnamedfile_name()
#
# A context manager for doing work on a temporary file, via the filename only.
#
# Note that a Windows restriction prevents us from using both the file
# descriptor and the file name of tempfile.NamedTemporaryFile, the same file
# cannot be opened twice at the same time. This wrapper makes it easier to
# operate in a Windows-friendly way when only filenames are needed.
#
# Takes care to delete the file even if interrupted by SIGTERM. Note that there
# is a race-condition, so this is done on a best-effort basis.
#
# Args:
# dir (str): A path to a parent directory for the temporary file, this is
# not optional for security reasons, please see below.
#
# Note that 'dir' should not be a directory that may be shared with potential
# attackers that have rights to affect the directory, e.g. the system temp
# directory. This is because an attacker can replace the temporary file with
# e.g. a symlink to another location, that the BuildStream user has rights to
# but the attacker does not.
#
# See here for more information:
# https://www.owasp.org/index.php/Insecure_Temporary_File
#
# Yields:
# (str): The temporary file name
#
@contextmanager
def _tempnamedfile_name(dir): # pylint: disable=redefined-builtin
filename = None

def rm_tempfile():
nonlocal filename
if filename is not None:
# Note that this code is re-entrant - it's possible for us to
# "delete while we're deleting" if we are responding to SIGTERM.
#
# For simplicity, choose to leak the file in this unlikely case,
# rather than introducing a scheme for handling the file sometimes
# being missing. Note that we will still leak tempfiles on forced
# termination anyway.
#
# Note that we must not try to delete the file more than once. If
# we delete the file then another temporary file can be created
# with the same name.
#
filename2 = filename
filename = None
os.remove(filename2)

with _signals.terminator(rm_tempfile):
fd, filename = tempfile.mkstemp(dir=dir)
os.close(fd)
try:
yield filename
finally:
rm_tempfile()


# _kill_process_tree()
#
# Brutally murder a process and all of its children
Expand Down Expand Up @@ -1521,14 +1430,6 @@ def _deduplicate(iterable, key=None):
yield element


# Like os.path.getmtime(), but returns the mtime of a link rather than
# the target, if the filesystem supports that.
#
def _get_link_mtime(path):
path_stat = os.lstat(path)
return path_stat.st_mtime


# _message_digest()
#
# Args:
Expand Down
Loading