Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Atomic/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,33 @@ def set_args(self, args):
def _info(self):
return self.d.info()

def mount(self):
def _try_ostree_mount(self, best_mountpoint_for_storage):
if best_mountpoint_for_storage:
mountpoint = os.path.join(self.syscontainers.get_ostree_repo_location(), "tmp/atomic-mount", str(os.getpid()), self.image)
if os.path.exists(mountpoint):
shutil.rmtree(mountpoint)
os.makedirs(mountpoint)
else:
mountpoint = self.mountpoint

d = OSTreeMount(self.args, mountpoint, live=self.live, shared=self.shared)
if d.mount(self.image, self.options):
self.mountpoint = mountpoint
return True

return False

# if best_mountpoint_for_storage the storage can modify the mountpoint so
# to optimize the checkout (for example OSTree requires this to create
# hard links on the same file system.
def mount(self, best_mountpoint_for_storage=False):

if not self.storage:
if self.is_duplicate_image(self.image):
raise ValueError("Found more than one Image with name {}; "
"please specify with --storage.".format(self.image))
try:
d = OSTreeMount(self.args, self.mountpoint, live=self.live, shared=self.shared)
if d.mount(self.image, self.options):
if self._try_ostree_mount(best_mountpoint_for_storage):
return
except GLib.Error: # pylint: disable=catching-non-exception
pass
Expand All @@ -167,8 +186,7 @@ def mount(self):

elif self.storage.lower() == "ostree":
try:
d = OSTreeMount(self.args, self.mountpoint, live=self.live, shared=self.shared)
if d.mount(self.image, self.options):
if self._try_ostree_mount(best_mountpoint_for_storage):
return
except GLib.Error: # pylint: disable=catching-non-exception
self._no_such_image()
Expand Down Expand Up @@ -713,7 +731,7 @@ def _clean_temp_container_by_path(self, path):
if not self.live:
self.d.remove_container(short_cid)
self._clean_tmp_image()

def getxattrfuncs():
# Python 3 has support for extended attributes in the os module, while
# Python 2 needs the xattr library. Detect if any is available.
Expand Down
30 changes: 14 additions & 16 deletions Atomic/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,24 @@ def get_scan_data(self):
def _mount_scan_rootfs(self, scan_list):
for docker_object in scan_list:
mount_path = os.path.join(self.chroot_dir, docker_object.id.replace("/", "_"))
self.mount_paths[os.path.basename(mount_path.rstrip('/'))] = docker_object.id
os.mkdir(mount_path)
if self.debug:
util.write_out("Created {}".format(mount_path))
self.mount(mountpoint=mount_path, image=docker_object.id)
docker_object.mount_path = mount_path
new_mount_path = self.mount(mountpoint=mount_path, image=docker_object.id)
if new_mount_path != mount_path:
rmtree(mount_path)
os.symlink(new_mount_path, mount_path)
self.mount_paths[new_mount_path.rstrip('/')] = docker_object.id
if self.debug:
util.write_out("Mounted {} to {}".format(docker_object.id, mount_path))

def _unmount_rootfs_in_dir(self):
for _dir in self.get_rootfs_paths():
rootfs_dir = os.path.join(self.chroot_dir, _dir)
for rootfs_dir in self.get_rootfs_paths():
if len(self.args.rootfs) == 0:
if os.path.ismount(rootfs_dir):
try:
self.unmount(rootfs_dir)
except (ValueError, mount.MountError):
pass
else:
# Clean up bind mounts if the chroot feature is used
mcmd = ['umount', rootfs_dir]
Expand All @@ -252,16 +255,10 @@ def _unmount_rootfs_in_dir(self):

def get_rootfs_paths(self):
"""
Returns the list of rootfs paths (not fully qualified); if defined,
returns self.rootfs_paths, else defines and returns it
Returns the list of rootfs paths (not fully qualified)
:return: list
"""
def _get_rootfs_paths():
return next(os.walk(self.chroot_dir))[1]

if len(self.rootfs_paths) == 0:
self.rootfs_paths = _get_rootfs_paths()
return self.rootfs_paths
return self.mount_paths.keys()

def output_results(self):
"""
Expand All @@ -274,7 +271,7 @@ def output_results(self):
if self.args.json:
util.output_json(json_results)
else:
uuid = self.mount_paths[os.path.basename(json_results['UUID']).rstrip('/')] if len(self.args.rootfs) == 0 \
uuid = self.mount_paths[json_results['UUID'].rstrip('/')] if len(self.args.rootfs) == 0 \
else self._get_roots_path_from_bind_name(json_file)

name1 = uuid if len(self.args.rootfs) > 1 else self._get_input_name_for_id(uuid)
Expand Down Expand Up @@ -443,7 +440,8 @@ def mount(self, mountpoint, image):
m.mountpoint = mountpoint
m.image = image
m.shared = True
m.mount()
m.mount(best_mountpoint_for_storage=True)
return m.mountpoint

def unmount(self, mountpoint):
m = mount.Mount()
Expand Down