Correct path comparisons for fs view (#25891)

* Fix path comparisons in copy views

* Get correct permissions

* Set group id though os

Co-authored-by: Philip Sakievich <psakiev@sanida.gov>
This commit is contained in:
psakievich 2021-09-27 10:51:38 -06:00 committed by GitHub
parent 33957f2745
commit df9d1dd1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -61,8 +61,8 @@ def view_copy(src, dst, view, spec=None):
Use spec and view to generate relocations
"""
shutil.copyfile(src, dst)
if spec:
shutil.copy2(src, dst)
if spec and not spec.external:
# Not metadata, we have to relocate it
# Get information on where to relocate from/to
@ -73,16 +73,17 @@ def view_copy(src, dst, view, spec=None):
# will have the old sbang location in their shebangs.
# TODO: Not sure which one to use...
import spack.hooks.sbang as sbang
orig_sbang = '#!/bin/bash {0}/bin/sbang'.format(spack.paths.spack_root)
new_sbang = sbang.sbang_shebang_line()
prefix_to_projection = OrderedDict({
spec.prefix: view.get_projection_for_spec(spec),
spack.paths.spack_root: view._root})
spec.prefix: view.get_projection_for_spec(spec)})
for dep in spec.traverse():
prefix_to_projection[dep.prefix] = \
view.get_projection_for_spec(dep)
if not dep.external:
prefix_to_projection[dep.prefix] = \
view.get_projection_for_spec(dep)
if spack.relocate.is_binary(dst):
spack.relocate.relocate_text_bin(
@ -96,6 +97,11 @@ def view_copy(src, dst, view, spec=None):
files=[dst],
prefixes=prefix_to_projection
)
try:
stat = os.stat(src)
os.chown(dst, stat.st_uid, stat.st_gid)
except OSError:
tty.debug('Can\'t change the permissions for %s' % dst)
def view_func_parser(parsed_name):

View File

@ -497,6 +497,7 @@ def _replace_prefix_bin(filename, byte_prefixes):
# We only care about this problem if we are about to replace
length_compatible = len(new_bytes) <= len(orig_bytes)
if not length_compatible:
tty.debug('Binary failing to relocate is %s' % filename)
raise BinaryTextReplaceError(orig_bytes, new_bytes)
pad_length = len(orig_bytes) - len(new_bytes)
padding = os.sep * pad_length