From d918107b4bac91cc9bc4b47738be8143717daaa7 Mon Sep 17 00:00:00 2001 From: Arnab Bose Date: Wed, 8 May 2024 21:13:27 +0530 Subject: [PATCH] Small fixes - Installation now copies the whole directory (will separately update PKGBUILD) - A fix to rollback Part of Issue #32 --- scripts/install-to-dest.sh | 13 +++++++++---- src/code/rollbacker.py | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/install-to-dest.sh b/scripts/install-to-dest.sh index ca4db69..bd0b6d7 100755 --- a/scripts/install-to-dest.sh +++ b/scripts/install-to-dest.sh @@ -27,11 +27,16 @@ cd $MY_PATH/.. readonly PKGNAME=yabsnap # This mirrors PKGBUILD with slight modifications. +pushd src/ +tar -cf - \ + $(find -type f -not -name "*_test.py" \( -name "*.py" -o -name "*.conf" \)) | + tar -xf - -C "$PKGDIR"/usr/share/"$PKGNAME"/ +pushd "$PKGDIR"/usr/share/"$PKGNAME"/ +chown -R root:root . +chmod -R u=rwX,go=rX . +popd +popd -for file in $(ls -A src/code/*.{py,conf} | grep -v "_test.py") -do - install -Dm 644 "$file" "$PKGDIR"/usr/share/"$PKGNAME"/code/"${file##*/}" -done cd artifacts install -Dm 644 services/"$PKGNAME".{service,timer} -t "$PKGDIR"/usr/lib/systemd/system/ install -Dm 664 pacman/*.hook -t "$PKGDIR"/usr/share/libalpm/hooks/ diff --git a/src/code/rollbacker.py b/src/code/rollbacker.py index 9b6fc78..a914c38 100644 --- a/src/code/rollbacker.py +++ b/src/code/rollbacker.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections + from . import configs from . import snap_operator from .mechanisms import snap_mechanisms @@ -20,20 +22,14 @@ def rollback(configs_iter: Iterable[configs.Config], path_suffix: str): - source_dests: list[tuple[str, str]] = [] + source_dests_by_snaptype: dict[snap_mechanisms.SnapType, list[tuple[str, str]]] = ( + collections.defaultdict(list) + ) for config in configs_iter: snap = snap_operator.find_target(config, path_suffix) if snap: - if snap.metadata.snap_type == snap_mechanisms.SnapType.BTRFS: - source_dests.append((snap.metadata.source, snap.target)) - else: - raise RuntimeError( - f"Cannot rollback snap of type {snap.metadata.snap_type} yet" - ) - print("\n".join(_rollback_btrfs_snapshots(source_dests))) - - -def _rollback_btrfs_snapshots(source_dests: list[tuple[str, str]]) -> list[str]: - return snap_mechanisms.get(snap_mechanisms.SnapType.BTRFS).rollback_gen( - source_dests - ) + source_dests_by_snaptype[config.snap_type].append( + (snap.metadata.source, snap.target) + ) + for snap_type, source_dests in sorted(source_dests_by_snaptype.items()): + print("\n".join(snap_mechanisms.get(snap_type).rollback_gen(source_dests)))