This is an automated email from the ASF dual-hosted git repository. github-bot pushed a commit to branch jmac/googlecas_and_virtual_directories_1 in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit d1aff2b6d3f1049bfd08ba88ce33a4f4de8cbb8b Author: Jim MacArthur <[email protected]> AuthorDate: Wed May 9 13:00:06 2018 +0100 Implement can_destroy flag in _filebaseddirectory.py --- buildstream/sandbox/Directory.py | 5 ++++- 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 0a60fce..f37fb98 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 975a4cc..50dca57 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:
