Skip to content

Commit 8684239

Browse files
committed
cmd-diff: refactor metal mounting code into helper
This way we can have more commands that can leverae this code for different "diffs" on the resulting mounted filesystems. Prep for a future commit.
1 parent f6f6bbb commit 8684239

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/cmd-diff

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ def run_guestfs_mount(image_path, mount_target):
361361
g.close()
362362

363363

364-
def diff_metal(diff_from, diff_to):
364+
# Generator that will mount up metal image filesystems and yield
365+
# the paths to be used for analysis and then clean up once given back
366+
# control.
367+
def diff_metal_helper(diff_from, diff_to):
365368
metal_from = get_metal_path(diff_from)
366369
metal_to = get_metal_path(diff_to)
367370

@@ -394,8 +397,8 @@ def diff_metal(diff_from, diff_to):
394397
if not p.is_alive():
395398
raise Exception(f"A guestfs process for {os.path.basename(d)} died unexpectedly.")
396399

397-
# Now that the mounts are live, we can diff them
398-
git_diff(mount_dir_from, mount_dir_to)
400+
# Allow the caller to operate on these values
401+
yield mount_dir_from, mount_dir_to
399402

400403
finally:
401404
# Unmount the FUSE binds, this will make the guestfs mount calls return
@@ -413,6 +416,11 @@ def diff_metal(diff_from, diff_to):
413416
shutdown_process(p_to)
414417

415418

419+
def diff_metal(diff_from, diff_to):
420+
for mount_dir_from, mount_dir_to in diff_metal_helper(diff_from, diff_to):
421+
git_diff(mount_dir_from, mount_dir_to)
422+
423+
416424
def diff_cmd_outputs(cmd, path_from, path_to, strategy: DiffCmdOutputStrategy = DiffCmdOutputStrategy.TEMPLATE):
417425
workingdir = None
418426
with tempfile.NamedTemporaryFile(prefix=cmd[0] + '-') as from_output, \

0 commit comments

Comments
 (0)