Skip to content

Conversation

@upils
Copy link
Contributor

@upils upils commented Apr 10, 2025

  • Have you signed the CLA?
  • Have you added an entry to the changelog (docs/reference/changelog.rst)?

Expand the chroot into a sandbox.

  • enable defining mounts
  • enable defining diversions
  • enable defining files to swap in the sandbox
  • clean dangling processes to be reasonably sure umounting the mountpoints will succeed.

Usage example https://github.com/canonical/imagecraft/tree/work/experiment-chroot

@upils upils force-pushed the work/experiment-chroot branch from 94f92fc to b8f6657 Compare April 10, 2025 12:05
@upils upils requested a review from cmatsuoka April 10, 2025 12:07
Signed-off-by: Paul Mars <[email protected]>
Comment on lines +46 to +47
def __init__(self, target: Path, content: str) -> None:
self._target = target
Copy link
Collaborator

@cmatsuoka cmatsuoka Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a name like ContentReplacer or (FileContentReplacer) and then use replace() and restore()? Or even a context manager for that so it could look like:

with FileContentReplacer("/etc/issue"):
    do_my_stuff()

If the context manager can't be used it could be something like:

d = FileContentReplacer("/etc/issue")
d.replace()
do_my_stuff()
d.restore()

But the context manager would make more sense in this use case imho.

Comment on lines +372 to +379
try:
self._setup()
child.start()
res, err = parent_conn.recv()
child.join()
finally:
logger.debug("[pid=%d] clean up the sandbox", os.getpid())
self._cleanup()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this try-finally could be a context manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants