#include <string.h>
#include <errno.h>
+#include "config.h"
#include "snapper/Comparison.h"
#include "snapper/Snapper.h"
#include "snapper/Log.h"
return files.getUndoStatistic();
}
+#ifdef ENABLE_XATTRS
+ XAUndoStatistic
+ Comparison::getXAUndoStatistic() const
+ {
+ if (getSnapshot1()->isCurrent())
+ throw IllegalSnapshotException();
+
+ return files.getXAUndoStatistic();
+ }
+#endif
+
vector<UndoStep>
Comparison::getUndoSteps() const
void umount() const;
UndoStatistic getUndoStatistic() const;
+#ifdef ENABLE_XATTRS
+ XAUndoStatistic getXAUndoStatistic() const;
+#endif
vector<UndoStep> getUndoSteps() const;
}
*/
bool
- File::modifyXattributes() const
+ File::modifyXattributes()
{
bool ret_val;
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) {
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
#ifndef SNAPPER_FILE_H
#define SNAPPER_FILE_H
-
+#include "config.h"
#include <sys/stat.h>
#include <string>
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
{
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; }
friend std::ostream& operator<<(std::ostream& s, const File& file);
+#ifdef ENABLE_XATTRS
+ XAUndoStatistic getXAUndoStatistic() const;
+#endif
private:
bool createParentDirectories(const string& path) const;
bool deleteAllTypes() const;
bool modifyAllTypes() const;
-#ifdef ENABLE_XATTRS
- bool modifyXattributes() const;
-#endif
+
const FilePaths* file_paths;
string name;
bool undo;
+#ifdef ENABLE_XATTRS
+ bool modifyXattributes();
+
+ unsigned int xaCreated;
+ unsigned int xaDeleted;
+ unsigned int xaReplaced;
+#endif
};
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); }
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)
{
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(); };
#include <iostream>
#include <fstream>
+#include "config.h"
#include "common.h"
#include <snapper/Snapper.h>
Snapshots::iterator second;
unsigned int numCreateErrors, numModifyErrors, numDeleteErrors;
+#ifdef ENABLE_XATTRS
+unsigned int xaCreate, xaReplace, xaDelete;
+#endif
void
}
+#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()
{
}
cout << "undoing done" << endl;
+
+#ifdef ENABLE_XATTRS
+ XAUndoStatistic xs = files.getXAUndoStatistic();
+ xaCreate = xs.numCreate;
+ xaReplace = xs.numReplace;
+ xaDelete = xs.numDelete;
+#endif
+
}
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);
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);
}