You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:47:18 UTC
[buildstream] 16/17: Implement can_destroy flag in
_filebaseddirectory.py
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch jmac/virtual_directories_test
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 2e8748a89bad059abf4fd4b218874ed44cd302a1
Author: Jim MacArthur <ji...@codethink.co.uk>
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 21a15fb..fd27f8e 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: