Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: projectatomic/atomic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fadcd8df12044f3314dba04904c013044ce5ee13
Choose a base ref
..
head repository: projectatomic/atomic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 412e981f1f130f23e639f559775c37247e15dc81
Choose a head ref
Showing with 17 additions and 7 deletions.
  1. +17 −7 Atomic/rpm_host_install.py
24 changes: 17 additions & 7 deletions Atomic/rpm_host_install.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
class RPMHostInstall(object):

@staticmethod
def copyfile(src, dest):
def copyfile(selinux_hnd, src, dest):
if os.path.isdir(src):
# add the directory only if it is empty, so we don't delete directories that
# weren't added by us. Anyway a non empty directory would be created by
@@ -25,11 +25,11 @@ def copyfile(src, dest):
os.symlink(linkto, dest)
return True
else:
if selinux_hnd is not None:
ctx = selinux.selabel_lookup_raw(selinux_hnd, dest, os.stat(src).st_mode)
selinux.setfscreatecon_raw(ctx[1])

shutil.copy2(src, dest)
try:
selinux.restorecon(dest)
except (TypeError, OSError):
pass
return True
return False

@@ -79,7 +79,14 @@ def rm_add_files_to_host(old_installed_files_checksum, exports, prefix="/", file
# if there is a directory hostfs/ under exports, copy these files to the host file system.
hostfs = os.path.join(exports, "hostfs")
new_installed_files_checksum = {}
if os.path.exists(hostfs):
if not os.path.exists(hostfs):
return new_isntalled_files_checksum

selinux_hnd = None
try:
if os.getuid() == 0 and selinux.is_selinux_enabled() != 0:
selinux_hnd = selinux.selabel_open(selinux.SELABEL_CTX_FILE, None, 0)

for root, dirs, files in os.walk(hostfs):
rel_root_path = os.path.relpath(root, hostfs)
if not os.path.exists(os.path.join(prefix, rel_root_path)):
@@ -110,10 +117,13 @@ def rm_add_files_to_host(old_installed_files_checksum, exports, prefix="/", file
shutil.copystat(src_file, dest_path)
created = True
else:
created = RPMHostInstall.copyfile(src_file, dest_path)
created = RPMHostInstall.copyfile(selinux_hnd, src_file, dest_path)

if created:
new_installed_files_checksum[rel_dest_path] = RPMHostInstall.file_checksum(dest_path)
finally:
if selinux_hnd is not None:
selinux.setfscreatecon_raw(None)

return new_installed_files_checksum