]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- add support for XA undo statistics
authorOndrej Kozina <okozina@redhat.com>
Mon, 25 Feb 2013 17:48:25 +0000 (18:48 +0100)
committerOndrej Kozina <okozina@redhat.com>
Wed, 27 Feb 2013 16:30:10 +0000 (17:30 +0100)
snapper/Comparison.cc
snapper/Comparison.h
snapper/File.cc
snapper/File.h
snapper/XAttributes.cc
snapper/XAttributes.h
testsuite-real/common.cc
testsuite-real/common.h
testsuite-real/xattrs1.cc

index 4db8f173ba6de772e206b8b58a74e1477567520c..100e967ae2470e2ee5ed52edf7732e246e6082b1 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include "config.h"
 #include "snapper/Comparison.h"
 #include "snapper/Snapper.h"
 #include "snapper/Log.h"
@@ -258,6 +259,17 @@ namespace snapper
        return files.getUndoStatistic();
     }
 
+#ifdef ENABLE_XATTRS
+    XAUndoStatistic
+    Comparison::getXAUndoStatistic() const
+    {
+        if (getSnapshot1()->isCurrent())
+            throw IllegalSnapshotException();
+
+        return files.getXAUndoStatistic();
+    }
+#endif
+
 
     vector<UndoStep>
     Comparison::getUndoSteps() const
index 7576c8367c04e574168c9b61c97a1060d7adb075..c0884c44ed32b3f0911f38709573337c1276cdc2 100644 (file)
@@ -50,6 +50,9 @@ namespace snapper
        void umount() const;
 
        UndoStatistic getUndoStatistic() const;
+#ifdef ENABLE_XATTRS
+        XAUndoStatistic getXAUndoStatistic() const;
+#endif
 
        vector<UndoStep> getUndoSteps() const;
 
index d5e916ae47532bf61520eb3a300f1fefd766bc0c..f1028c29b3517852fb57a0f06bb27d43f3d113d5 100644 (file)
@@ -590,7 +590,7 @@ namespace snapper
     }
 */
     bool
-    File::modifyXattributes() const
+    File::modifyXattributes()
     {
         bool ret_val;
 
@@ -601,6 +601,12 @@ namespace snapper
             XAModification xa_mod(xa_src, xa_dest);
             y2deb("xa_modmap(xa_dest) object: " << xa_mod);
 
+            xaCreated = xa_mod.getXaCreateNum();
+            xaDeleted = xa_mod.getXaDeleteNum();
+            xaReplaced = xa_mod.getXaReplaceNum();
+
+            y2deb("xaCreated:" << xaCreated << ",xaDeleted:" << xaDeleted << ",xaReplaced:" << xaReplaced);
+
             ret_val = xa_mod.serializeTo(getAbsolutePath(LOC_SYSTEM));
         }
         catch (XAttributesException xae) {
@@ -610,6 +616,42 @@ namespace snapper
         return ret_val;
     }
 
+    XAUndoStatistic& operator+=(XAUndoStatistic &out, const XAUndoStatistic &src)
+    {
+        out.numCreate += src.numCreate;
+        out.numDelete += src.numDelete;
+        out.numReplace += src.numReplace;
+
+        return out;
+    }
+
+    XAUndoStatistic
+    File::getXAUndoStatistic() const
+    {
+        XAUndoStatistic xs;
+
+        xs.numCreate = xaCreated;
+        xs.numDelete = xaDeleted;
+        xs.numReplace = xaReplaced;
+
+        return xs;
+    }
+
+    XAUndoStatistic
+    Files::getXAUndoStatistic() const
+    {
+        XAUndoStatistic xs;
+
+        for (vector<File>::const_iterator it = entries.begin(); it != entries.end(); ++it)
+        {
+            if (it->getUndo() && (it->getPreToPostStatus() & (DELETED | XATTRS | TYPE)))
+            {
+                xs += it->getXAUndoStatistic();
+            }
+        }
+
+        return xs;
+    }
 #endif
 
     bool
index c61e69c99468b4793c24e0f95104e4ba5337a187..f3843925dc629b161e848b83de162e23a4e1948d 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef SNAPPER_FILE_H
 #define SNAPPER_FILE_H
 
-
+#include "config.h"
 #include <sys/stat.h>
 
 #include <string>
@@ -77,6 +77,19 @@ namespace snapper
        friend std::ostream& operator<<(std::ostream& s, const UndoStatistic& rs);
     };
 
+#ifdef ENABLE_XATTRS
+    struct XAUndoStatistic
+    {
+        XAUndoStatistic(): numCreate(0), numReplace(0), numDelete(0) {}
+
+        unsigned int numCreate;
+        unsigned int numReplace;
+        unsigned int numDelete;
+
+        friend XAUndoStatistic& operator+=(XAUndoStatistic&, const XAUndoStatistic&);
+    };
+#endif
+
 
     struct UndoStep
     {
@@ -103,6 +116,9 @@ namespace snapper
        File(const FilePaths* file_paths, const string& name, unsigned int pre_to_post_status)
            : file_paths(file_paths), name(name), pre_to_post_status(pre_to_post_status),
              pre_to_system_status(-1), post_to_system_status(-1), undo(false)
+#ifdef ENABLE_XATTRS
+              ,xaCreated(0), xaDeleted(0), xaReplaced(0)
+#endif
        {}
 
        const string& getName() const { return name; }
@@ -123,6 +139,9 @@ namespace snapper
 
        friend std::ostream& operator<<(std::ostream& s, const File& file);
 
+#ifdef ENABLE_XATTRS
+            XAUndoStatistic getXAUndoStatistic() const;
+#endif
     private:
 
        bool createParentDirectories(const string& path) const;
@@ -135,9 +154,7 @@ namespace snapper
        bool deleteAllTypes() const;
 
        bool modifyAllTypes() const;
-#ifdef ENABLE_XATTRS
-        bool modifyXattributes() const;
-#endif
+
        const FilePaths* file_paths;
 
        string name;
@@ -148,6 +165,13 @@ namespace snapper
 
        bool undo;
 
+#ifdef ENABLE_XATTRS
+            bool modifyXattributes();
+
+            unsigned int xaCreated;
+            unsigned int xaDeleted;
+            unsigned int xaReplaced;
+#endif
     };
 
 
@@ -184,7 +208,9 @@ namespace snapper
        vector<UndoStep> getUndoSteps() const;
 
        bool doUndoStep(const UndoStep& undo_step);
-
+#ifdef ENABLE_XATTRS
+        XAUndoStatistic getXAUndoStatistic() const;
+#endif
     protected:
 
        void push_back(File file) { entries.push_back(file); }
index 211707dfa5d69f165000c90b205816f11f32966a..cd8e87ea5193fdfd9e6ac28627611c511e1cd9e9 100644 (file)
@@ -384,6 +384,24 @@ namespace snapper
         return true;
     }
 
+    unsigned int
+    XAModification::getXaCreateNum() const
+    {
+        return this->operator[](XA_CREATE).size();
+    }
+
+    unsigned int
+    XAModification::getXaDeleteNum() const
+    {
+        return this->operator[](XA_DELETE).size();
+    }
+
+    unsigned int
+    XAModification::getXaReplaceNum() const
+    {
+        return this->operator[](XA_REPLACE).size();
+    }
+
     ostream&
     operator<<(ostream &out, const XAModification &xa_mod)
     {
index 9319aeb44ebba17572d512bd33287175614357bb..c1e8b201721a7e1b9a9cf11083e76c47f13cf886 100644 (file)
@@ -93,6 +93,11 @@ namespace snapper
 
             bool isEmpty() const;
             bool serializeTo(const string&) const;
+
+            unsigned int getXaCreateNum() const;
+            unsigned int getXaDeleteNum() const;
+            unsigned int getXaReplaceNum() const;
+
             xa_mod_citer cbegin() const { return xamodmap.begin(); };
             xa_mod_citer cend() const { return xamodmap.end(); };
 
index e9048297b84b3f3b7344b4bc4a99a7a83def40b9..7c1da5ced536bd0b1a2851b28e5d16e0f2fa2592 100644 (file)
@@ -4,6 +4,7 @@
 #include <iostream>
 #include <fstream>
 
+#include "config.h"
 #include "common.h"
 
 #include <snapper/Snapper.h>
@@ -27,6 +28,9 @@ Snapshots::iterator first;
 Snapshots::iterator second;
 
 unsigned int numCreateErrors, numModifyErrors, numDeleteErrors;
+#ifdef ENABLE_XATTRS
+unsigned int xaCreate, xaReplace, xaDelete;
+#endif
 
 
 void
@@ -81,6 +85,16 @@ check_undo_statistics(unsigned int numCreate, unsigned int numModify, unsigned i
 }
 
 
+#ifdef ENABLE_XATTRS
+void
+check_xa_undo_statistics(unsigned int xaNumCreate, unsigned xaNumReplace, unsigned int xaNumDelete)
+{
+    check_equal(xaCreate, xaNumCreate);
+    check_equal(xaDelete, xaNumDelete);
+    check_equal(xaReplace, xaNumReplace);
+}
+#endif
+
 void
 undo()
 {
@@ -120,6 +134,14 @@ undo()
     }
 
     cout << "undoing done" << endl;
+
+#ifdef ENABLE_XATTRS
+    XAUndoStatistic xs = files.getXAUndoStatistic();
+    xaCreate = xs.numCreate;
+    xaReplace = xs.numReplace;
+    xaDelete = xs.numDelete;
+#endif
+
 }
 
 
index 1b4d1d3898110c8c01991b6eee2cfb83fcb43a04..7ea57107864369c8b82f3360b7f980dedd98a894 100644 (file)
@@ -50,6 +50,7 @@ void first_snapshot();
 void second_snapshot();
 void check_undo_statistics(unsigned int numCreate, unsigned int numModify,
                           unsigned int numDelete);
+void check_xa_undo_statistics(unsigned int xaNumCreate, unsigned int xaNumReplace, unsigned int xaNumDelete);
 void undo();
 void check_undo_errors(unsigned int numCreate, unsigned int numModify,
                       unsigned int numDelete);
index ed90a7181e306af39f900c339197c5282f99a236..ebf2589ed14949e9addac87b464e62d247a5baa6 100644 (file)
@@ -21,16 +21,21 @@ main()
     run_command("setfacl -b file1");
     xattr_remove("user.aaa","/testsuite/file1");
     xattr_replace("user.bbb", "bbb-new-value", "/testsuite/file1");
+    xattr_create("user.ccc", "ccc-value", "/testsuite/file1");
 
     second_snapshot();
 
+    undo();
+
     check_undo_statistics(0, 1, 0);
 
-    undo();
+    check_xa_undo_statistics(2, 1, 1);
 
     check_undo_errors(0, 0, 0);
 
     check_first();
 
+    cleanup();
+
     exit(EXIT_SUCCESS);
 }