Isolate util/file_permissions
This commit is contained in:
parent
1f0a8755c7
commit
330a5c0010
@ -5,18 +5,18 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import spack.util.file_permissions as fp
|
import spack.package_prefs as pp
|
||||||
|
|
||||||
|
|
||||||
def post_install(spec, explicit=None):
|
def post_install(spec, explicit=None):
|
||||||
if not spec.external:
|
if not spec.external:
|
||||||
fp.set_permissions_by_spec(spec.prefix, spec)
|
pp.set_permissions_by_spec(spec.prefix, spec)
|
||||||
|
|
||||||
# os.walk explicitly set not to follow links
|
# os.walk explicitly set not to follow links
|
||||||
for root, dirs, files in os.walk(spec.prefix, followlinks=False):
|
for root, dirs, files in os.walk(spec.prefix, followlinks=False):
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
if not os.path.islink(os.path.join(root, d)):
|
if not os.path.islink(os.path.join(root, d)):
|
||||||
fp.set_permissions_by_spec(os.path.join(root, d), spec)
|
pp.set_permissions_by_spec(os.path.join(root, d), spec)
|
||||||
for f in files:
|
for f in files:
|
||||||
if not os.path.islink(os.path.join(root, f)):
|
if not os.path.islink(os.path.join(root, f)):
|
||||||
fp.set_permissions_by_spec(os.path.join(root, f), spec)
|
pp.set_permissions_by_spec(os.path.join(root, f), spec)
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
import spack.environment
|
import spack.environment
|
||||||
import spack.error
|
import spack.error
|
||||||
import spack.modules.common
|
import spack.modules.common
|
||||||
|
import spack.package_prefs as pp
|
||||||
import spack.paths
|
import spack.paths
|
||||||
import spack.projections as proj
|
import spack.projections as proj
|
||||||
import spack.repo
|
import spack.repo
|
||||||
@ -54,7 +55,6 @@
|
|||||||
import spack.store
|
import spack.store
|
||||||
import spack.tengine as tengine
|
import spack.tengine as tengine
|
||||||
import spack.util.environment
|
import spack.util.environment
|
||||||
import spack.util.file_permissions as fp
|
|
||||||
import spack.util.path
|
import spack.util.path
|
||||||
import spack.util.spack_yaml as syaml
|
import spack.util.spack_yaml as syaml
|
||||||
from spack.context import Context
|
from spack.context import Context
|
||||||
@ -969,7 +969,7 @@ def write(self, overwrite=False):
|
|||||||
|
|
||||||
# Set the file permissions of the module to match that of the package
|
# Set the file permissions of the module to match that of the package
|
||||||
if os.path.exists(self.layout.filename):
|
if os.path.exists(self.layout.filename):
|
||||||
fp.set_permissions_by_spec(self.layout.filename, self.spec)
|
pp.set_permissions_by_spec(self.layout.filename, self.spec)
|
||||||
|
|
||||||
# Symlink defaults if needed
|
# Symlink defaults if needed
|
||||||
self.update_module_defaults()
|
self.update_module_defaults()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
import stat
|
import stat
|
||||||
import warnings
|
import warnings
|
||||||
|
import os
|
||||||
|
|
||||||
import spack.error
|
import spack.error
|
||||||
import spack.repo
|
import spack.repo
|
||||||
@ -11,6 +12,7 @@
|
|||||||
from spack.config import ConfigError
|
from spack.config import ConfigError
|
||||||
from spack.util.path import canonicalize_path
|
from spack.util.path import canonicalize_path
|
||||||
from spack.version import Version
|
from spack.version import Version
|
||||||
|
import spack.util.file_permissions as fp
|
||||||
|
|
||||||
_lesser_spec_types = {"compiler": spack.spec.CompilerSpec, "version": Version}
|
_lesser_spec_types = {"compiler": spack.spec.CompilerSpec, "version": Version}
|
||||||
|
|
||||||
@ -296,5 +298,16 @@ def get_package_group(spec):
|
|||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
|
def set_permissions_by_spec(path, spec):
|
||||||
|
# Get permissions for spec
|
||||||
|
if os.path.isdir(path):
|
||||||
|
perms = get_package_dir_permissions(spec)
|
||||||
|
else:
|
||||||
|
perms = get_package_permissions(spec)
|
||||||
|
group = get_package_group(spec)
|
||||||
|
|
||||||
|
fp.set_permissions(path, perms, group)
|
||||||
|
|
||||||
|
|
||||||
class VirtualInPackagesYAMLError(spack.error.SpackError):
|
class VirtualInPackagesYAMLError(spack.error.SpackError):
|
||||||
"""Raised when a disallowed virtual is found in packages.yaml"""
|
"""Raised when a disallowed virtual is found in packages.yaml"""
|
||||||
|
@ -8,21 +8,9 @@
|
|||||||
|
|
||||||
import llnl.util.filesystem as fs
|
import llnl.util.filesystem as fs
|
||||||
|
|
||||||
import spack.package_prefs as pp
|
|
||||||
from spack.util.error import UtilityError
|
from spack.util.error import UtilityError
|
||||||
|
|
||||||
|
|
||||||
def set_permissions_by_spec(path, spec):
|
|
||||||
# Get permissions for spec
|
|
||||||
if os.path.isdir(path):
|
|
||||||
perms = pp.get_package_dir_permissions(spec)
|
|
||||||
else:
|
|
||||||
perms = pp.get_package_permissions(spec)
|
|
||||||
group = pp.get_package_group(spec)
|
|
||||||
|
|
||||||
set_permissions(path, perms, group)
|
|
||||||
|
|
||||||
|
|
||||||
def set_permissions(path, perms, group=None):
|
def set_permissions(path, perms, group=None):
|
||||||
# Preserve higher-order bits of file permissions
|
# Preserve higher-order bits of file permissions
|
||||||
perms |= os.stat(path).st_mode & (st.S_ISUID | st.S_ISGID | st.S_ISVTX)
|
perms |= os.stat(path).st_mode & (st.S_ISUID | st.S_ISGID | st.S_ISVTX)
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
|
|
||||||
|
import spack.package_prefs as pp
|
||||||
import spack.filesystem_view
|
import spack.filesystem_view
|
||||||
import spack.store
|
import spack.store
|
||||||
import spack.util.file_permissions as fp
|
|
||||||
import spack.util.spack_json as sjson
|
import spack.util.spack_json as sjson
|
||||||
from spack.package_base import spack_times_log
|
from spack.package_base import spack_times_log
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ def write_manifest(spec):
|
|||||||
with open(manifest_file, "w") as f:
|
with open(manifest_file, "w") as f:
|
||||||
sjson.dump(manifest, f)
|
sjson.dump(manifest, f)
|
||||||
|
|
||||||
fp.set_permissions_by_spec(manifest_file, spec)
|
pp.set_permissions_by_spec(manifest_file, spec)
|
||||||
|
|
||||||
|
|
||||||
def check_entry(path, data):
|
def check_entry(path, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user