diff options
author | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-05-09 13:00:06 +0100 |
---|---|---|
committer | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-07-05 14:07:43 +0100 |
commit | 27060bfe09f7bab2117fbe9284437703fe9a0618 (patch) | |
tree | 3b423b6c022a8844034e477c14fae46232b0d98f | |
parent | e3f4f97a3a0a9a0cb44228c8f4a76130414e6986 (diff) | |
download | buildstream-27060bfe09f7bab2117fbe9284437703fe9a0618.tar.gz |
Implement can_destroy flag in _filebaseddirectory.py
-rw-r--r-- | buildstream/sandbox/Directory.py | 5 | ||||
-rw-r--r-- | buildstream/sandbox/_filebaseddirectory.py | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/buildstream/sandbox/Directory.py b/buildstream/sandbox/Directory.py index 0a60fce0e..f37fb98ad 100644 --- a/buildstream/sandbox/Directory.py +++ b/buildstream/sandbox/Directory.py @@ -80,7 +80,7 @@ class Directory(): raise NotImplementedError() - def export_files(self, to_directory: str, can_link: bool = False) -> None: + def export_files(self, to_directory: str, can_link: bool = False, can_destroy: bool = False) -> None: """Copies everything from this into to_directory. Arguments: @@ -91,6 +91,9 @@ class Directory(): can_link (bool): Whether we can create hard links in to_directory instead of copying. Setting this does not guarantee hard links will be used. + can_destroy (bool): Can we destroy the data already in this + directory when exporting? If set, this may allow data to be + moved rather than copied which will be quicker. """ raise NotImplementedError() diff --git a/buildstream/sandbox/_filebaseddirectory.py b/buildstream/sandbox/_filebaseddirectory.py index 975a4ccb0..50dca573b 100644 --- a/buildstream/sandbox/_filebaseddirectory.py +++ b/buildstream/sandbox/_filebaseddirectory.py @@ -188,7 +188,7 @@ class FileBasedDirectory(Directory): """ _set_deterministic_user(self.external_directory) - def export_files(self, to_directory: str, can_link: bool = False) -> None: + def export_files(self, to_directory: str, can_link: bool = False, can_destroy: bool = False) -> None: """Copies everything from this into to_directory. Arguments: @@ -200,6 +200,17 @@ class FileBasedDirectory(Directory): instead of copying. """ + + if can_destroy: + # Try a simple rename of the sandbox root; if that + # doesnt cut it, then do the regular link files code path + try: + os.rename(self.external_directory, to_directory) + return + except OSError: + # Proceed using normal link/copy + pass + if can_link: link_files(self.external_directory, to_directory) else: |