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

Versioning based on btrfs snapshots #3420

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Free method and rename it
Borgvall committed Jul 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0820a307dff0095e9e32ec52ba653a4dace17322
31 changes: 15 additions & 16 deletions bottles/backend/managers/btrfssubvolume.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,19 @@ def _delete_subvolume(path):
error.add_note(f"Fallback to 'shutil.rmtree()' failed with: '{e}'")
raise error

def try_create_bottle_snapshots_handle(bottle_path):
"""Try to create a bottle snapshots handle.
Checks if the bottle states can be stored as btrfs snapshots and if no
states have been stored by FVS versioning system. Returns
BottleSnapshotsHandle, if checks succeed, None otherwise.
"""
if not btrfsutil.is_subvolume(bottle_path):
return None
if os.path.exists(os.path.join(bottle_path, ".fvs")):
return None
return BottleSnapshotsHandle(bottle_path)

class BottleSnapshotsHandle:
"""Handle the snapshots of a single bottle created as btrfs subvolume.
"""
@@ -36,8 +49,8 @@ class BottleSnapshotsHandle:
def __init__(self, bottle_path):
"""Internal should not be called directly.
Use BtrfsSubvolumeManager.create_bottle_snapshots_handle() to
potentially create an instance.
Use try_create_bottle_snapshots_handle() to potentially create an
instance.
"""
self._bottle_path = bottle_path
bottles_dir, bottle_name = os.path.split(bottle_path)
@@ -125,17 +138,3 @@ def create_bottle_as_subvolume(bottle_path) -> bool:
return False
else:
return True

@staticmethod
def create_bottle_snapshots_handle(bottle_path):
"""Try to create a bottle snapshots handle.
Checks if the bottle states can be stored as btrfs snapshots and if no
states have been stored by FVS versioning system. Returns
BottleSnapshotsHandle, if checks succeed, None otherwise.
"""
if not btrfsutil.is_subvolume(bottle_path):
return None
if os.path.exists(os.path.join(bottle_path, ".fvs")):
return None
return BottleSnapshotsHandle(bottle_path)