Merge pull request #43 from wesbarnett/fix/firstsnap

Fix installation error
This commit is contained in:
Wes Barnett, PhD 2021-04-15 20:28:37 -04:00 committed by GitHub
commit 95ad2669f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 70 deletions

View file

@ -1,28 +0,0 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016, 2017, 2018 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
[Trigger]
Operation = Remove
Type = Package
Target = snap-pac
[Action]
Description = You are removing snap-pac. No post transaction snapshots will be taken.
Depends = snap-pac
When = PreTransaction
Exec = /usr/bin/bash -c "rm -f /tmp/snap-pac-pre_*"

View file

@ -1,28 +0,0 @@
# snap-pac
# https://github.com/wesbarnett/snap-pac
# Copyright (C) 2016, 2017, 2018 James W. Barnett
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
[Trigger]
Operation = Install
Type = Package
Target = snap-pac
[Action]
Description = You are installing snap-pac, so no post transaction snapshots will be taken.
Depends = snap-pac
When = PostTransaction
Exec = /usr/bin/true

View file

@ -38,7 +38,6 @@ class SnapperCmd:
self.cmd.append("--no-dbus")
self.cmd.extend([
f"--config {config} create",
f"--type {snapshot_type}",
f"--cleanup-algorithm {cleanup_algorithm}",
"--print-number"
])
@ -50,7 +49,11 @@ class SnapperCmd:
if pre_number is not None:
self.cmd.append(f"--pre-number {pre_number}")
else:
raise ValueError("snapshot type specified as 'post' but no pre snapshot number passed.")
logging.debug("snapshot type specified as 'post' but no pre snapshot number, "
"so setting snapshot type to 'single'. If installing "
"snap-pac this is normal.")
snapshot_type = "single"
self.cmd.append(f"--type {snapshot_type}")
def __call__(self):
return os.popen(self.__str__()).read().rstrip("\n")
@ -148,7 +151,9 @@ class Prefile:
try:
pre_number = self.file.read_text()
except FileNotFoundError:
raise FileNotFoundError(f"prefile {self.file} not found. Ensure you have run the pre snapshot first.")
pre_number = None
logging.debug(f"prefile {self.file} not found. Ensure you have run the pre snapshot first. "
"If installing snap-pac this is normal.")
else:
self.file.unlink()
return pre_number

View file

@ -10,27 +10,32 @@ from scripts.snap_pac import check_skip, ConfigProcessor, get_snapper_configs, P
@pytest.mark.parametrize("snapper_cmd, actual_cmd", [
(
SnapperCmd("root", "pre", "number", "foo"),
"snapper --config root create --type pre --cleanup-algorithm number --print-number --description \"foo\""
"snapper --config root create --cleanup-algorithm number --print-number --description \"foo\" --type pre"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234),
"snapper --config root create --type post --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234"
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", True, 1234),
"snapper --no-dbus --config root create --type post --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234"
"snapper --no-dbus --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234, "important=yes"),
"snapper --config root create --type post --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"important=yes\" --pre-number 1234"
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"important=yes\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, 1234, "foo=bar,important=yes"),
"snapper --config root create --type post --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"foo=bar,important=yes\" --pre-number 1234"
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"foo=bar,important=yes\" --pre-number 1234 --type post"
),
(
SnapperCmd("root", "post", "number", "bar", False, None, "foo=bar,important=yes"),
"snapper --config root create --cleanup-algorithm number --print-number"
" --description \"bar\" --userdata \"foo=bar,important=yes\" --type single"
)
])
def test_snapper_cmd(snapper_cmd, actual_cmd):
@ -114,5 +119,4 @@ def test_prefile_read():
def test_no_prefile():
prefile = Prefile("foo-pre-file-not-found", "post")
with pytest.raises(FileNotFoundError):
prefile.read()
assert prefile.read() is None