Skip to content

Commit

Permalink
Merge pull request #2171 from kacf/ext4_image_symlinks
Browse files Browse the repository at this point in the history
build: Add symlink creation to container image manipulation API.
  • Loading branch information
lluiscampos authored Sep 30, 2024
2 parents 9c54159 + 7ab949a commit 650e991
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions meta-mender-qemu/scripts/docker/ext4_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def get(remote_path, local_path, rootfs):
subprocess.check_call(["debugfs", "-R", "dump -p %s %s" % (remote_path, local_path), rootfs],
stderr=subprocess.STDOUT)

def put(local_path, remote_path, rootfs, remote_path_mkdir_p=False):
# Debugfs doesn't produce error if a file doesn't exist, so let's check that first.
assert os.path.exists(local_path), f"\"{local_path}\" doesn't exist"
EXT4_PUT = 0
EXT4_SYMLINK = 1

def _put_common(operation, local_path, remote_path, rootfs, remote_path_mkdir_p=False):
proc = subprocess.Popen(["debugfs", "-w", rootfs], stdin=subprocess.PIPE,
stderr=subprocess.STDOUT)
if remote_path_mkdir_p:
Expand All @@ -33,11 +33,25 @@ def put(local_path, remote_path, rootfs, remote_path_mkdir_p=False):
proc.stdin.write(("mkdir %s\n" % parent).encode())
proc.stdin.write(("cd %s\n" % os.path.dirname(remote_path)).encode())
proc.stdin.write(("rm %s\n" % os.path.basename(remote_path)).encode())
proc.stdin.write(("write %s %s\n" % (local_path, os.path.basename(remote_path))).encode())
if operation == EXT4_PUT:
proc.stdin.write(("write %s %s\n" % (local_path, os.path.basename(remote_path))).encode())
elif operation == EXT4_SYMLINK:
proc.stdin.write(("symlink %s %s\n" % (os.path.basename(remote_path), local_path)).encode())
else:
assert False, "_put_common: Invalid operation"
proc.stdin.close()
ret = proc.wait()
assert ret == 0

def put(local_path, remote_path, rootfs, remote_path_mkdir_p=False):
# Debugfs doesn't produce error if a file doesn't exist, so let's check that first.
assert os.path.exists(local_path), f"\"{local_path}\" doesn't exist"

return _put_common(EXT4_PUT, local_path, remote_path, rootfs, remote_path_mkdir_p=remote_path_mkdir_p)

def symlink(target, remote_path, rootfs, remote_path_mkdir_p=False):
return _put_common(EXT4_SYMLINK, target, remote_path, rootfs, remote_path_mkdir_p=remote_path_mkdir_p)

def extract_ext4(img, rootfs):
return _manipulate_ext4(img=img, rootfs=rootfs, write=False)

Expand Down

0 comments on commit 650e991

Please sign in to comment.