def deploy_files(staging_directory, instance_directory, file_list, username, problem_class):
"""
Copies the list of files from the staging directory to the instance directory.
Will properly set permissions and setgid files based on their type.
"""
# get uid and gid for default and problem user
user = getpwnam(username)
default = getpwnam(deploy_config.default_user)
for f in file_list:
# copy the file over, making the directories as needed
output_path = join(instance_directory, f.path)
if not os.path.isdir(os.path.dirname(output_path)):
os.makedirs(os.path.dirname(output_path))
if not isinstance(f, Directory):
if isinstance(f, PreTemplatedFile):
file_source = join(staging_directory, "__pre_templated", f.path)
else:
file_source = join(staging_directory, f.path)
shutil.copy2(file_source, output_path)
# set the ownership based on the type of file
if isinstance(f, ProtectedFile) or isinstance(f, ExecutableFile):
os.chown(output_path, default.pw_uid, user.pw_gid)
else:
uid = default.pw_uid if f.user is None else getpwnam(f.user).pw_uid
gid = default.pw_gid if f.group is None else getgrnam(f.group).gr_gid
os.chown(output_path, uid, gid)
# set the permissions appropriately
os.chmod(output_path, f.permissions)
if issubclass(problem_class, Service):
os.chown(instance_directory, default.pw_uid, user.pw_gid)
os.chmod(instance_directory, 0o750)
评论列表
文章目录