Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add symlink creation to container image manipulation API. #2171

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
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