in antlir/compiler/items/install_file.py [0:0]
def __init__(self, **kwargs) -> None:
customize_stat_options(kwargs, default_mode=None) # Defaulted later
source = kwargs["source"]
dest = Path(make_path_normal_relative(kwargs.pop("dest")))
# The 3 separate `*_mode` arguments must be set instead of `mode` for
# directory sources.
popped_args = ["mode", "exe_mode", "data_mode", "dir_mode"]
mode, dir_mode, exe_mode, data_mode = (
kwargs.pop(a, None) for a in popped_args
)
st_source = os.stat(str(source), follow_symlinks=False)
if stat.S_ISDIR(st_source.st_mode):
assert mode is None, "Cannot use `mode` for directory sources."
self._paths = tuple(
_recurse_into_source(
source,
dest,
dir_mode=dir_mode or _DIR_MODE,
exe_mode=exe_mode or _EXE_MODE,
data_mode=data_mode or _DATA_MODE,
)
)
elif stat.S_ISREG(st_source.st_mode):
assert {dir_mode, exe_mode, data_mode} == {
None
}, "Cannot use `{dir,exe,data}_mode` for file sources."
if mode is None:
# This tests whether the build repo user can execute the
# file. This is a very natural test for build artifacts,
# and files in the repo. Note that this can be affected if
# the ambient umask is pathological, which is why
# `compiler.py` checks the umask.
mode = _EXE_MODE if os.access(source, os.X_OK) else _DATA_MODE
self._paths = (
_InstallablePath(
source=source, provides=ProvidesFile(path=dest), mode=mode
),
)
else:
raise RuntimeError(
f"{source} must be a regular file or directory, got {st_source}"
)
super().__init__(dest=dest, **kwargs)