]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- lock config during list and cleanup commands and in zypper plugin
authorArvin Schnell <aschnell@suse.de>
Wed, 7 Feb 2024 10:20:08 +0000 (11:20 +0100)
committerArvin Schnell <aschnell@suse.de>
Wed, 7 Feb 2024 10:20:08 +0000 (11:20 +0100)
15 files changed:
client/Makefile.am
client/cleanup.cc
client/cmd-list.cc
client/commands.cc
client/commands.h
client/locker.cc [new file with mode: 0644]
client/locker.h [new file with mode: 0644]
client/proxy-dbus.cc
client/proxy-dbus.h
client/proxy-lib.h
client/proxy.h
examples/python/lock-config.py
package/snapper.changes
zypp-plugin/snapper-zypp-plugin.cc
zypp-plugin/snapper-zypp-plugin.h

index 814f5051ec82fc970206bafe8d069a4b6e6cbe7c..80a2a41b0e38383abf4cdf82d41ff9616411fb87 100644 (file)
@@ -43,6 +43,7 @@ snapper_SOURCES =                                     \
        proxy.cc                proxy.h                 \
        proxy-dbus.cc           proxy-dbus.h            \
        proxy-lib.cc            proxy-lib.h             \
+       locker.cc               locker.h                \
        misc.cc                 misc.h                  \
        MyFiles.cc              MyFiles.h               \
        GlobalOptions.cc        GlobalOptions.h
@@ -64,6 +65,7 @@ systemd_helper_SOURCES =              \
        proxy.cc        proxy.h         \
        proxy-dbus.cc   proxy-dbus.h    \
        proxy-lib.cc    proxy-lib.h     \
+       locker.cc       locker.h        \
        misc.cc         misc.h
 
 systemd_helper_LDADD = libclient.la ../snapper/libsnapper.la utils/libutils.la ../dbus/libdbus.la
index 626a0b653427a5753aba6e937a341244ae1b4e08..cb67b389f08abad7b13e3d35f0e2e5ef99952fc6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2016-2021] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -34,6 +34,7 @@
 #include "utils/equal-date.h"
 #include "utils/HumanString.h"
 #include "cleanup.h"
+#include "locker.h"
 
 
 using namespace std;
@@ -106,7 +107,7 @@ class Cleaner
 public:
 
     Cleaner(ProxySnapper* snapper, bool verbose, const Parameters& parameters)
-       : snapper(snapper), verbose(verbose), parameters(parameters) {}
+       : snapper(snapper), locker(snapper), verbose(verbose), parameters(parameters) {}
 
     virtual ~Cleaner() {}
 
@@ -158,6 +159,8 @@ protected:
 
     ProxySnapper* snapper;
 
+    Locker locker;
+
     const bool verbose;
     const Parameters& parameters;
 
index 352a8f03626a87957cb4922265f17c6ca4e0e2ba..75d66f3ac600d86ceeda10fb3eac1bd298055eb1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -32,6 +32,7 @@
 #include "utils/text.h"
 #include "GlobalOptions.h"
 #include "proxy.h"
+#include "locker.h"
 #include "misc.h"
 #include "utils/TableFormatter.h"
 #include "utils/CsvFormatter.h"
@@ -138,6 +139,13 @@ namespace snapper
            bool skip_snapshot(const ProxySnapshot& snapshot, ListMode list_mode) const;
 
            const ProxySnapper* snapper;
+
+       private:
+
+           Locker locker;
+
+       public:
+
            const ProxySnapshots& snapshots;
 
        private:
@@ -168,8 +176,8 @@ namespace snapper
 
 
        OutputHelper::OutputHelper(const ProxySnapper* snapper, const vector<Column>& columns)
-           : snapper(snapper), snapshots(snapper->getSnapshots()), default_snapshot(snapshots.end()),
-             active_snapshot(snapshots.end())
+           : snapper(snapper), locker(snapper), snapshots(snapper->getSnapshots()),
+             default_snapshot(snapshots.end()), active_snapshot(snapshots.end())
        {
            try
            {
index 54fd6fd3859994da6cb0f5c4a283d3c14499fa6c..d467371022ce9db3934224bf57e40f1aa250b983 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -690,6 +690,30 @@ command_sync(DBus::Connection& conn, const string& config_name)
 }
 
 
+void
+command_lock_config(DBus::Connection& conn, const string& config_name)
+{
+    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "LockConfig");
+
+    DBus::Marshaller marshaller(call);
+    marshaller << config_name;
+
+    conn.send_with_reply_and_block(call);
+}
+
+
+void
+command_unlock_config(DBus::Connection& conn, const string& config_name)
+{
+    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "UnlockConfig");
+
+    DBus::Marshaller marshaller(call);
+    marshaller << config_name;
+
+    conn.send_with_reply_and_block(call);
+}
+
+
 vector<XReport>
 command_get_plugins_report(DBus::Connection& conn)
 {
index 6550b0b56e46bc5d287419760718d78100082b59..f5139be74f260d3d0cada804ecebb25cde814e0d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -149,6 +149,12 @@ command_query_quota(DBus::Connection& conn, const string& config_name);
 FreeSpaceData
 command_query_free_space(DBus::Connection& conn, const string& config_name);
 
+void
+command_lock_config(DBus::Connection& conn, const string& config_name);
+
+void
+command_unlock_config(DBus::Connection& conn, const string& config_name);
+
 void
 command_sync(DBus::Connection& conn, const string& config_name);
 
diff --git a/client/locker.cc b/client/locker.cc
new file mode 100644 (file)
index 0000000..bea024e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2024 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 "locker.h"
+
+
+namespace snapper
+{
+
+    Locker::Locker(const ProxySnapper* snapper)
+       : snapper(snapper)
+    {
+       snapper->lock_config();
+    }
+
+
+    Locker::~Locker()
+    {
+       snapper->unlock_config();
+    }
+
+}
diff --git a/client/locker.h b/client/locker.h
new file mode 100644 (file)
index 0000000..41d30ae
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2024 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 "proxy.h"
+
+
+namespace snapper
+{
+
+    class Locker
+    {
+
+    public:
+
+       Locker(const ProxySnapper* snapper);
+       ~Locker();
+
+    private:
+
+       const ProxySnapper* snapper;
+
+    };
+
+}
index eba552c6d7113af66827a53c3cc543052835baa0..7d998d5aa63919e6d6f32ebc6b6003d06338531e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -81,6 +81,20 @@ ProxySnapshotDbus::getUsedSpace() const
 }
 
 
+void
+ProxySnapperDbus::lock_config() const
+{
+    command_lock_config(conn(), config_name);
+}
+
+
+void
+ProxySnapperDbus::unlock_config() const
+{
+    command_unlock_config(conn(), config_name);
+}
+
+
 string
 ProxySnapshotDbus::mountFilesystemSnapshot(bool user_request) const
 {
index f7f06adc0716dd3e09e6ec5c916cd29b5ced1366..205fc92c726a125aabdc398499e06dfb0d3f9f53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -155,6 +155,9 @@ public:
 
     virtual void calculateUsedSpace() const override;
 
+    virtual void lock_config() const override;
+    virtual void unlock_config() const override;
+
     DBus::Connection& conn() const;
 
 private:
index 89357f0da138390f068d2504560618cf7067cf5e..e17fd84fbb0b0105a6cd7342b4df2b1c09eec265 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -138,6 +138,9 @@ public:
 
     virtual void calculateUsedSpace() const override { snapper->calculateUsedSpace(); }
 
+    virtual void lock_config() const override {}
+    virtual void unlock_config() const override {}
+
     std::unique_ptr<Snapper> snapper;
 
 private:
index 56a46a6fa8f6f53f4e6887d9e62d33188c5ea27a..0156a2b2c6cc3d5de7b977790c2dc50191dcce23 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -253,6 +253,9 @@ public:
 
     virtual void calculateUsedSpace() const = 0;
 
+    virtual void lock_config() const = 0;
+    virtual void unlock_config() const = 0;
+
 };
 
 
index 0a626428f60475919f42e43def408361cd8a0da6..fa68e29ccc07b27637cc40b472a48748944cb6c4 100755 (executable)
@@ -10,7 +10,15 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S
 
 
 snapper.LockConfig("root")
+print("locked")
+
+snapper.LockConfig("root")
+snapper.UnlockConfig("root")
+print("still locked")
 
 sleep(10)
 
 snapper.UnlockConfig("root")
+print("unlocked")
+
+sleep(10)
index 1e05f94b4e8f6c6a1ff94268779c2f046acf88dd..8ffe4e6f29db0c6e0dfb985f5758e567764ae246 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Wed Feb 07 11:16:40 CET 2024 - aschnell@suse.com
+
+- lock config during list and cleanup commands and in zypper plugin
+  (gh#openSUSE/snapper#867)
+
 -------------------------------------------------------------------
 Fri Dec 08 09:06:30 CET 2023 - aschnell@suse.com
 
index aee4b80faf6b610fbc1d326ca6e8f04a452047e5..7d1e9dbb97173be97b501d5ac7aa72636902abd2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2019-2023] SUSE LLC
+ * Copyright (c) [2019-2024] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -97,7 +97,7 @@ SnapperZyppCommitPlugin::SnapperZyppCommitPlugin(const ProgramOptions& opts)
 ZyppCommitPlugin::Message
 SnapperZyppCommitPlugin::plugin_begin(const Message& msg)
 {
-    y2mil("PLUGINBEGIN");
+    y2mil("PLUGIN BEGIN");
 
     userdata = get_userdata(msg);
 
@@ -108,7 +108,7 @@ SnapperZyppCommitPlugin::plugin_begin(const Message& msg)
 ZyppCommitPlugin::Message
 SnapperZyppCommitPlugin::plugin_end(const Message& msg)
 {
-    y2mil("PLUGINEND");
+    y2mil("PLUGIN END");
 
     return ack();
 }
@@ -117,7 +117,7 @@ SnapperZyppCommitPlugin::plugin_end(const Message& msg)
 ZyppCommitPlugin::Message
 SnapperZyppCommitPlugin::commit_begin(const Message& msg)
 {
-    y2mil("COMMITBEGIN");
+    y2mil("COMMIT BEGIN");
 
     set<string> solvables = get_solvables(msg, Phase::BEFORE);
     y2deb("solvables: " << solvables);
@@ -128,6 +128,16 @@ SnapperZyppCommitPlugin::commit_begin(const Message& msg)
 
     if (found || important)
     {
+       try
+       {
+           y2deb("lock config");
+           command_lock_config(dbus_conn, snapper_cfg);
+       }
+       catch (const Exception& ex)
+       {
+           SN_CAUGHT(ex);
+       }
+
        userdata["important"] = important ? "yes" : "no";
 
        try
@@ -155,7 +165,7 @@ SnapperZyppCommitPlugin::commit_begin(const Message& msg)
 ZyppCommitPlugin::Message
 SnapperZyppCommitPlugin::commit_end(const Message& msg)
 {
-    y2mil("COMMITEND");
+    y2mil("COMMIT END");
 
     if (pre_snapshot_num != 0)
     {
@@ -228,6 +238,16 @@ SnapperZyppCommitPlugin::commit_end(const Message& msg)
                SN_CAUGHT(ex);
            }
        }
+
+       try
+       {
+           y2deb("unlock config");
+           command_unlock_config(dbus_conn, snapper_cfg);
+       }
+       catch (const Exception& ex)
+       {
+           SN_CAUGHT(ex);
+       }
     }
 
     return ack();
index c2c2215b26ed2ffa51e46103a0ab462d5da8fd2f..023e923e3afe13e8dc41286407313a973da351a4 100644 (file)
@@ -65,7 +65,7 @@ private:
     const string snapper_cfg;
 
     DBus::Connection dbus_conn;
-    unsigned int pre_snapshot_num;
+    unsigned int pre_snapshot_num = 0;
     string snapshot_description;
     map<string, string> userdata;