summaryrefslogtreecommitdiff
path: root/src/buildstream
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-05-01 15:41:38 +0100
committerRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-05-22 14:09:23 +0100
commit3b44a7785e22ee82dee28533b1e825c26491b2b3 (patch)
treee9fa8ae4b69c816fd5d061d275d5f27f4dabc940 /src/buildstream
parentc3f96e1bc32f1728619b144e1d0120349411df66 (diff)
downloadbuildstream-3b44a7785e22ee82dee28533b1e825c26491b2b3.tar.gz
Directory: add `import_single_file` method
This a new method which deals with importing a single file. Implemented for both FileBasedDirectory and CasBasedDirectory. Part of #983
Diffstat (limited to 'src/buildstream')
-rw-r--r--src/buildstream/storage/_casbaseddirectory.py12
-rw-r--r--src/buildstream/storage/_filebaseddirectory.py10
-rw-r--r--src/buildstream/storage/directory.py4
3 files changed, 26 insertions, 0 deletions
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py
index 2aff29b98..12ef482dc 100644
--- a/src/buildstream/storage/_casbaseddirectory.py
+++ b/src/buildstream/storage/_casbaseddirectory.py
@@ -386,6 +386,18 @@ class CasBasedDirectory(Directory):
return result
+ def import_single_file(self, srcpath):
+ result = FileListResult()
+ if self._check_replacement(os.path.basename(srcpath),
+ os.path.dirname(srcpath),
+ result):
+ self._add_file(os.path.dirname(srcpath),
+ os.path.basename(srcpath),
+ modified=os.path.basename(srcpath)
+ in result.overwritten)
+ result.files_written.append(srcpath)
+ return result
+
def set_deterministic_mtime(self):
""" Sets a static modification time for all regular files in this directory.
Since we don't store any modification time, we don't need to do anything.
diff --git a/src/buildstream/storage/_filebaseddirectory.py b/src/buildstream/storage/_filebaseddirectory.py
index 9a746f731..90911da86 100644
--- a/src/buildstream/storage/_filebaseddirectory.py
+++ b/src/buildstream/storage/_filebaseddirectory.py
@@ -28,6 +28,7 @@ See also: :ref:`sandboxing`.
"""
import os
+import shutil
import stat
import time
@@ -111,6 +112,15 @@ class FileBasedDirectory(Directory):
os.utime(os.path.join(self.external_directory, f), times=(cur_time, cur_time))
return import_result
+ def import_single_file(self, srcpath):
+ dstpath = os.path.join(self.external_directory, os.path.basename(srcpath))
+ result = FileListResult()
+ if os.path.exists(dstpath):
+ result.ignored.append(dstpath)
+ else:
+ shutil.copyfile(srcpath, dstpath, follow_symlinks=False)
+ return result
+
def _mark_changed(self):
pass
diff --git a/src/buildstream/storage/directory.py b/src/buildstream/storage/directory.py
index bad818fef..c40e1bdb9 100644
--- a/src/buildstream/storage/directory.py
+++ b/src/buildstream/storage/directory.py
@@ -103,6 +103,10 @@ class Directory():
raise NotImplementedError()
+ def import_single_file(self, external_pathspec):
+ """Imports a single file from an external path"""
+ raise NotImplementedError()
+
def export_files(self, to_directory, *, can_link=False, can_destroy=False):
"""Copies everything from this into to_directory.