From: Arvin Schnell Date: Fri, 14 Jul 2023 12:09:38 +0000 (+0200) Subject: - enable snapper-timeline.timer when adjusting config X-Git-Tag: v0.10.6~6^2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d91fdd0471819fd96f19e8cd69e83dd40d282978;p=thirdparty%2Fsnapper.git - enable snapper-timeline.timer when adjusting config --- diff --git a/LIBVERSION b/LIBVERSION index a3fcc712..21c8c7b4 100644 --- a/LIBVERSION +++ b/LIBVERSION @@ -1 +1 @@ -7.1.0 +7.1.1 diff --git a/package/snapper.changes b/package/snapper.changes index 83c82419..0b1c6e84 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Jul 14 14:05:56 CEST 2023 - aschnell@suse.com + +- enable snapper-timeline.timer when adjusting config using + snapper (gh#openSUSE/snapper#788) + ------------------------------------------------------------------- Wed Jul 12 09:03:42 CEST 2023 - aschnell@suse.com diff --git a/snapper/Makefile.am b/snapper/Makefile.am index 0a78c4ea..383b45eb 100644 --- a/snapper/Makefile.am +++ b/snapper/Makefile.am @@ -26,6 +26,7 @@ libsnapper_la_SOURCES = \ AsciiFile.cc AsciiFile.h \ Acls.cc Acls.h \ Hooks.cc Hooks.h \ + Systemctl.cc Systemctl.h \ Exception.cc Exception.h \ SnapperTmpl.h \ SnapperTypes.h \ diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 7d20068b..9504b050 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -47,6 +47,7 @@ #include "snapper/Exception.h" #include "snapper/Hooks.h" #include "snapper/ComparisonImpl.h" +#include "snapper/Systemctl.h" #ifdef ENABLE_BTRFS #include "snapper/Btrfs.h" #include "snapper/BtrfsUtils.h" @@ -94,7 +95,8 @@ namespace snapper { y2mil("Snapper constructor"); y2mil("libsnapper version " VERSION); - y2mil("config_name:" << config_name << " disable_filters:" << disable_filters); + y2mil("config_name:" << config_name << " root_prefix:" << root_prefix << + " disable_filters:" << disable_filters); try { @@ -120,7 +122,7 @@ namespace snapper #endif bool sync_acl; - if (config_info->get_value(KEY_SYNC_ACL, sync_acl) && sync_acl == true) + if (config_info->get_value(KEY_SYNC_ACL, sync_acl) && sync_acl) syncAcl(); y2mil("subvolume:" << config_info->get_subvolume() << " filesystem:" << @@ -410,6 +412,8 @@ namespace snapper SN_THROW(CreateConfigFailedException(e.what())); } + bool timeline_create = false; + try { SysconfigFile config(template_file); @@ -420,6 +424,8 @@ namespace snapper config.set_value(KEY_FSTYPE, filesystem->fstype()); config.save(); + + config.get_value(KEY_TIMELINE_CREATE, timeline_create); } catch (const Exception& e) { @@ -450,6 +456,11 @@ namespace snapper SN_RETHROW(e); } + if (timeline_create) + { + systemctl_enable_timeline(true); + } + Hooks::create_config(Hooks::Stage::POST_ACTION, subvolume, filesystem.get()); } @@ -523,6 +534,8 @@ namespace snapper SN_THROW(DeleteConfigFailedException("modifying sysconfig-file failed")); } + // TODO potentially disable snapper-timeline.timer + Hooks::delete_config(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem()); } @@ -541,9 +554,25 @@ namespace snapper raw.find(KEY_SYNC_ACL) != raw.end()) { bool sync_acl; - if (config_info->get_value(KEY_SYNC_ACL, sync_acl) && sync_acl == true) + if (config_info->get_value(KEY_SYNC_ACL, sync_acl) && sync_acl) syncAcl(); } + + if (raw.find(KEY_TIMELINE_CREATE) != raw.end()) + { + bool timeline_create; + if (config_info->get_value(KEY_TIMELINE_CREATE, timeline_create)) + { + if (timeline_create) + { + systemctl_enable_timeline(true); + } + else + { + // TODO potentially disable snapper-timeline.timer + } + } + } } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 73d7a200..ba6d6dd5 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -211,6 +211,8 @@ namespace snapper void syncInfoDir(SDir& dir) const; + // const std::string root_prefix; // TODO ABI change + ConfigInfo* config_info = nullptr; Filesystem* filesystem = nullptr; diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index cf218ab0..154f069b 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -1,6 +1,6 @@ /* * Copyright (c) [2004-2014] Novell, Inc. - * Copyright (c) [2020-2022] SUSE LLC + * Copyright (c) [2020-2023] SUSE LLC * * All Rights Reserved. * @@ -47,6 +47,8 @@ #define SH_BIN "/bin/sh" +#define SYSTEMCTL_BIN "/usr/bin/systemctl" + // keys from the config files @@ -57,6 +59,7 @@ #define KEY_ALLOW_GROUPS "ALLOW_GROUPS" #define KEY_SYNC_ACL "SYNC_ACL" #define KEY_COMPRESSION "COMPRESSION" +#define KEY_TIMELINE_CREATE "TIMELINE_CREATE" #endif diff --git a/snapper/Systemctl.cc b/snapper/Systemctl.cc new file mode 100644 index 00000000..982e1b4d --- /dev/null +++ b/snapper/Systemctl.cc @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "snapper/SystemCmd.h" +#include "snapper/SnapperDefines.h" + + +namespace snapper +{ + + void + systemctl_enable_unit(bool enable, bool now, const string& name) + { + // When run in a chroot system the enable command works but the start command + // fails (which is likely what we want). + + SystemCmd cmd(SYSTEMCTL_BIN " " + string(enable ? "enable " : "disable ") + + string(now ? "--now " : "") + name); + } + + + void + systemctl_enable_timeline(bool enable, bool now) + { + systemctl_enable_unit(enable, now, "snapper-timeline.timer"); + } + +} diff --git a/snapper/Systemctl.h b/snapper/Systemctl.h new file mode 100644 index 00000000..c4bb6309 --- /dev/null +++ b/snapper/Systemctl.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +namespace snapper +{ + + void systemctl_enable_timeline(bool enable, bool now = true); + +}