]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- enable snapper-timeline.timer when adjusting config 826/head
authorArvin Schnell <aschnell@suse.de>
Fri, 14 Jul 2023 12:09:38 +0000 (14:09 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 14 Jul 2023 12:09:38 +0000 (14:09 +0200)
LIBVERSION
package/snapper.changes
snapper/Makefile.am
snapper/Snapper.cc
snapper/Snapper.h
snapper/SnapperDefines.h
snapper/Systemctl.cc [new file with mode: 0644]
snapper/Systemctl.h [new file with mode: 0644]

index a3fcc7121bbab0e2221463e4493d1454f1b67252..21c8c7b46b8993bd95ff730695cad0d26e4239f3 100644 (file)
@@ -1 +1 @@
-7.1.0
+7.1.1
index 83c8241984858be2c6c7183787516210c173ab07..0b1c6e84f7406843078d34587f3cf114cb8c905b 100644 (file)
@@ -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
 
index 0a78c4ea3b17a8d4977e55820c5171d4da2320c5..383b45eb8657779c0731f73b1db7be992b75a927 100644 (file)
@@ -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                                  \
index 7d20068bbea32a0e565e52a16b75fbf2cafba6cc..9504b0507e7a31794f8aa58c03e414c699fc4b60 100644 (file)
@@ -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
+               }
+           }
+       }
     }
 
 
index 73d7a2002ea5de761858f4972617c9e5a9dd15f5..ba6d6dd5ee53995fe2d245220cfa899b5354f0b9 100644 (file)
@@ -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;
index cf218ab00871f289293c56e3adb961b41f25c7b1..154f069b4a85a680c1cbd35dc513e7ce94f1bfcd 100644 (file)
@@ -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 (file)
index 0000000..982e1b4
--- /dev/null
@@ -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 (file)
index 0000000..c4bb630
--- /dev/null
@@ -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);
+
+}