summaryrefslogtreecommitdiff
path: root/include_server/mirror_path.py
diff options
context:
space:
mode:
Diffstat (limited to 'include_server/mirror_path.py')
-rwxr-xr-xinclude_server/mirror_path.py49
1 files changed, 35 insertions, 14 deletions
diff --git a/include_server/mirror_path.py b/include_server/mirror_path.py
index 8b92933..dcf83eb 100755
--- a/include_server/mirror_path.py
+++ b/include_server/mirror_path.py
@@ -43,12 +43,16 @@ class MirrorPath(object):
def __init__(self,
simple_build_stat,
- canonical_path):
+ canonical_path,
+ realpath_map,
+ systemdir_prefix_cache):
"""Constructor.
Arguments:
simple_build_stat: object of type SimpleBuildStat
canonical_path: function of type CanonicalPath
+ realpath_map: a CanonicalMapToIndex; see cache_basics.py
+ systemdir_prefix_cache: a SystemdirPrefixCache; see cache_basics.py.
"""
assert isinstance(simple_build_stat, cache_basics.SimpleBuildStat)
assert isinstance(canonical_path, cache_basics.CanonicalPath)
@@ -61,6 +65,8 @@ class MirrorPath(object):
self.simple_build_stat = simple_build_stat
self.canonical_path = canonical_path
self.must_exist_dirs = []
+ self.realpath_map = realpath_map
+ self.systemdir_prefix_cache = systemdir_prefix_cache
def Links(self):
"""Return the list of symbolic links created."""
@@ -90,9 +96,10 @@ class MirrorPath(object):
# destinations exist, and replicate symbolic links where necessary.
while filepath and filepath != '/':
if (filepath, current_dir_idx) in link_stat:
- # Filepath is already mirrored
- return
+ # Filepath is already mirrored
+ return
link_stat.add((filepath, current_dir_idx))
+
# Process suffix of filepath by
# - making sure that the mirrored real path of the prefix exists,
# - and that the suffix if a symbolic link
@@ -109,18 +116,32 @@ class MirrorPath(object):
# And, its counterpart under root
root_prefix_real = root + prefix_real
- # Make sure that root_prefix_real is there
+ # Make sure that the parent, root_prefix_real, is there
if not lookup(root_prefix_real):
- if not os.path.isdir(root_prefix_real):
- self.must_exist_dirs.append(root_prefix_real)
- os.makedirs(root_prefix_real)
- self.simple_build_stat.cache[root_prefix_real] = True
-
+ # We have not been in this real location before.
+ if not os.path.isdir(root_prefix_real):
+ # Now check that the parent of the link is not under a default system
+ # dir. If it is, then we assume that the parent and indeed the
+ # link itself exist on the server as well, and thus, don't need to
+ # be mirrored.
+ realpath_map = self.realpath_map
+ realpath_idx = realpath_map.Index(prefix_real)
+ if not self.systemdir_prefix_cache.StartsWithSystemdir(realpath_idx,
+ realpath_map):
+ # Not under default system dir. Mark this directory as one that
+ # must always be created on the server.
+ self.must_exist_dirs.append(root_prefix_real)
+ # Create parent path in mirror directory.
+ os.makedirs(root_prefix_real)
+ else:
+ break
+ self.simple_build_stat.cache[root_prefix_real] = True
assert os.path.isdir(root_prefix_real)
- # Create the mirrored symbolic link if applicable
+ # Create the mirrored symbolic link if applicable.
if os.path.islink(filepath):
- link_name = root_prefix_real + '/' + suffix
- if not os.path.exists(link_name):
- os.symlink(self.canonical_path.Canonicalize(filepath), link_name)
- self.links.append(link_name)
+ link_name = root_prefix_real + '/' + suffix
+ if not os.path.exists(link_name):
+ os.symlink(self.canonical_path.Canonicalize(filepath),
+ link_name)
+ self.links.append(link_name)
filepath = prefix_filepath