summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-02-10 16:27:59 +0000
committerJürg Billeter <j@bitron.ch>2020-02-10 16:27:59 +0000
commit87999583c18ec367444e4c0aa7c1deeb04ab07d6 (patch)
tree097a85c62959ac790b3ee8d07055c367df567c8f
parent0591b0c8b038aa9f054b295748f3423384711d50 (diff)
parentb5477b27c821f1e2e35ff84e850786af0522f492 (diff)
downloadbuildstream-87999583c18ec367444e4c0aa7c1deeb04ab07d6.tar.gz
Merge branch 'juerg/remove-unused' into 'master'
Remove unused code See merge request BuildStream/buildstream!1817
-rw-r--r--src/buildstream/_cas/cascache.py16
-rw-r--r--src/buildstream/sandbox/_mounter.py148
-rw-r--r--src/buildstream/utils.py11
-rw-r--r--tests/sandboxes/mounting/mount_simple.py52
4 files changed, 0 insertions, 227 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index bb2abc6c8..083c8e8dc 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -547,22 +547,6 @@ class CASCache:
# Local Private Methods #
################################################
- def _get_subdir(self, tree, subdir):
- head, name = os.path.split(subdir)
- if head:
- tree = self._get_subdir(tree, head)
-
- directory = remote_execution_pb2.Directory()
-
- with open(self.objpath(tree), "rb") as f:
- directory.ParseFromString(f.read())
-
- for dirnode in directory.directories:
- if dirnode.name == name:
- return dirnode.digest
-
- raise CASCacheError("Subdirectory {} not found".format(name))
-
def _reachable_refs_dir(self, reachable, tree, update_mtime=False, check_exists=False):
if tree.hash in reachable:
return
diff --git a/src/buildstream/sandbox/_mounter.py b/src/buildstream/sandbox/_mounter.py
deleted file mode 100644
index 3adf8ff5b..000000000
--- a/src/buildstream/sandbox/_mounter.py
+++ /dev/null
@@ -1,148 +0,0 @@
-#
-# Copyright (C) 2017 Codethink Limited
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-#
-# Authors:
-# Tristan Maat <tristan.maat@codethink.co.uk>
-
-import sys
-from contextlib import contextmanager
-
-from .._exceptions import SandboxError
-from .. import utils, _signals
-
-
-# A class to wrap the `mount` and `umount` system commands
-class Mounter:
- @classmethod
- def _mount(cls, dest, src=None, mount_type=None, stdout=None, stderr=None, options=None, flags=None):
-
- if stdout is None:
- stdout = sys.stdout
- if stderr is None:
- stderr = sys.stderr
-
- argv = [utils.get_host_tool("mount")]
- if mount_type:
- argv.extend(["-t", mount_type])
- if options:
- argv.extend(["-o", options])
- if flags:
- argv.extend(flags)
-
- if src is not None:
- argv += [src]
- argv += [dest]
-
- status, _ = utils._call(argv, terminate=True, stdout=stdout, stderr=stderr)
-
- if status != 0:
- raise SandboxError("`{}` failed with exit code {}".format(" ".join(argv), status))
-
- return dest
-
- @classmethod
- def _umount(cls, path, stdout=None, stderr=None):
- if stdout is None:
- stdout = sys.stdout
- if stderr is None:
- stderr = sys.stderr
-
- cmd = [utils.get_host_tool("umount"), "-R", path]
- status, _ = utils._call(cmd, terminate=True, stdout=stdout, stderr=stderr)
-
- if status != 0:
- raise SandboxError("`{}` failed with exit code {}".format(" ".join(cmd), status))
-
- # mount()
- #
- # A wrapper for the `mount` command. The device is unmounted when
- # the context is left.
- #
- # Args:
- # dest (str) - The directory to mount to
- # src (str) - The directory to mount
- # stdout (file) - stdout
- # stderr (file) - stderr
- # mount_type (str|None) - The mount type (can be omitted or None)
- # kwargs - Arguments to pass to the mount command, such as `ro=True`
- #
- # Yields:
- # (str) The path to the destination
- #
- @classmethod
- @contextmanager
- def mount(cls, dest, src=None, stdout=None, stderr=None, mount_type=None, **kwargs):
- if stdout is None:
- stdout = sys.stdout
- if stderr is None:
- stderr = sys.stderr
-
- def kill_proc():
- cls._umount(dest, stdout, stderr)
-
- options = ",".join([key for key, val in kwargs.items() if val])
-
- path = cls._mount(dest, src, mount_type, stdout=stdout, stderr=stderr, options=options)
- try:
- with _signals.terminator(kill_proc):
- yield path
- finally:
- cls._umount(dest, stdout, stderr)
-
- # bind_mount()
- #
- # Mount a directory to a different location (a hardlink for all
- # intents and purposes). The directory is unmounted when the
- # context is left.
- #
- # Args:
- # dest (str) - The directory to mount to
- # src (str) - The directory to mount
- # stdout (file) - stdout
- # stderr (file) - stderr
- # kwargs - Arguments to pass to the mount command, such as `ro=True`
- #
- # Yields:
- # (str) The path to the destination
- #
- # While this is equivalent to `mount --rbind`, this option may not
- # exist and can be dangerous, requiring careful cleanupIt is
- # recommended to use this function over a manual mount invocation.
- #
- @classmethod
- @contextmanager
- def bind_mount(cls, dest, src=None, stdout=None, stderr=None, **kwargs):
- if stdout is None:
- stdout = sys.stdout
- if stderr is None:
- stderr = sys.stderr
-
- def kill_proc():
- cls._umount(dest, stdout, stderr)
-
- kwargs["rbind"] = True
- options = ",".join([key for key, val in kwargs.items() if val])
-
- path = cls._mount(dest, src, None, stdout, stderr, options)
-
- try:
- with _signals.terminator(kill_proc):
- # Make the rbind a slave to avoid unmounting vital devices in
- # /proc
- cls._mount(dest, flags=["--make-rslave"])
- yield path
- finally:
- cls._umount(dest, stdout, stderr)
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 9593f3e75..2b6c2761b 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -1059,17 +1059,6 @@ def _process_list(
actionfunc(srcpath, destpath, result=result)
- elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode):
- # Block or character device. Put contents of st_dev in a mknod.
- if not safe_remove(destpath):
- result.ignored.append(path)
- continue
-
- if os.path.lexists(destpath):
- os.remove(destpath)
- os.mknod(destpath, file_stat.st_mode, file_stat.st_rdev)
- os.chmod(destpath, file_stat.st_mode)
-
elif stat.S_ISFIFO(mode):
os.mkfifo(destpath, mode)
diff --git a/tests/sandboxes/mounting/mount_simple.py b/tests/sandboxes/mounting/mount_simple.py
deleted file mode 100644
index 0e78a5603..000000000
--- a/tests/sandboxes/mounting/mount_simple.py
+++ /dev/null
@@ -1,52 +0,0 @@
-import os
-import tempfile
-from contextlib import ExitStack
-
-import pytest
-
-from buildstream.sandbox._mounter import Mounter
-
-
-@pytest.mark.skipif(not os.geteuid() == 0, reason="requires root permissions")
-def test_bind_mount():
- with ExitStack() as stack:
- src = stack.enter_context(tempfile.TemporaryDirectory())
- target = stack.enter_context(tempfile.TemporaryDirectory())
-
- with open(os.path.join(src, "test"), "a") as test:
- test.write("Test")
-
- with Mounter.bind_mount(target, src) as dest:
- # Ensure we get the correct path back
- assert dest == target
-
- # Ensure we can access files from src from target
- with open(os.path.join(target, "test"), "r") as test:
- assert test.read() == "Test"
-
- # Ensure the files from src are gone from target
- with pytest.raises(FileNotFoundError):
- with open(os.path.join(target, "test"), "r"):
- # Actual contents don't matter
- pass
-
- # Ensure the files in src are still in src
- with open(os.path.join(src, "test"), "r") as test:
- assert test.read() == "Test"
-
-
-@pytest.mark.skipif(not os.geteuid() == 0, reason="requires root permissions")
-def test_mount_proc():
- with ExitStack() as stack:
- src = "/proc"
- target = stack.enter_context(tempfile.TemporaryDirectory())
-
- with Mounter.mount(target, src, mount_type="proc", ro=True) as dest:
- # Ensure we get the correct path back
- assert dest == target
-
- # Ensure /proc is actually mounted
- assert os.listdir(src) == os.listdir(target)
-
- # Ensure /proc is unmounted correctly
- assert os.listdir(target) == []