# Makefile.am for snapper
#
-SUBDIRS = snapper examples tools data
+SUBDIRS = snapper examples tools data testsuite-real
AUTOMAKE_OPTIONS = foreign dist-bzip2 no-dist-gzip
tools/Makefile
tools/utils/Makefile
data/Makefile
+ testsuite-real/Makefile
package/snapper.spec:snapper.spec.in
)
bool
Files::doRollback()
{
+ y2mil("begin rollback");
+
for (vector<File>::reverse_iterator it = entries.rbegin(); it != entries.rend(); ++it)
{
if (it->getRollback())
}
}
+ y2mil("end rollback");
+
return true;
}
iterator end() { return entries.end(); }
const_iterator end() const { return entries.end(); }
+ bool empty() const { return entries.empty(); }
+
iterator find(const string& name);
const_iterator find(const string& name) const;
}
+ Snapshots::const_iterator
+ Snapper::getSnapshotCurrent() const
+ {
+ return snapshots.getSnapshotCurrent();
+ }
+
+
Snapshots::iterator
Snapper::createSingleSnapshot(string description)
{
Snapshots& getSnapshots() { return snapshots; }
const Snapshots& getSnapshots() const { return snapshots; }
+ Snapshots::const_iterator getSnapshotCurrent() const;
+
Snapshots::iterator createSingleSnapshot(string description);
Snapshots::iterator createPreSnapshot(string description);
Snapshots::iterator createPostSnapshot(Snapshots::const_iterator pre);
const_iterator findPost(const_iterator pre) const;
+ const_iterator getSnapshotCurrent() const { return entries.begin(); }
+
private:
void initialize();
--- /dev/null
+*.o
+simple1
+permissions1
+owner1
--- /dev/null
+
+CAUTION
+-------
+
+The programs here destroy data on your disks!
+
--- /dev/null
+#
+# Makefile.am for snapper/testsuite-real
+#
+
+INCLUDES = -I$(top_srcdir)
+
+LDADD = ../snapper/libsnapper.la
+
+noinst_PROGRAMS = simple1 permissions1 owner1
+
+simple1_SOURCES = simple1.cc common.h common.cc
+
+permissions1_SOURCES = permissions1.cc common.h common.cc
+
+owner1_SOURCES = owner1.cc common.h common.cc
+
--- /dev/null
+
+#include <stdlib.h>
+#include <glob.h>
+#include <iostream>
+#include <fstream>
+
+#include "common.h"
+
+#include <snapper/Snapper.h>
+#include <snapper/Factory.h>
+#include <snapper/Snapshot.h>
+#include <snapper/File.h>
+
+#include "snapper/AppUtil.h"
+
+
+extern char* program_invocation_short_name;
+
+
+using namespace snapper;
+
+#define ROOTDIR "/test"
+
+Snapper* sh = NULL;
+
+Snapshots::iterator first;
+Snapshots::iterator second;
+
+
+void
+setup()
+{
+ system("/usr/bin/find " ROOTDIR " -mindepth 1 -maxdepth 1 -not -path " ROOTDIR "/snapshots "
+ "-exec rm -r {} \\;");
+
+ initDefaultLogger();
+
+ sh = createSnapper(ROOTDIR);
+}
+
+
+void
+first_snapshot()
+{
+ first = sh->createPreSnapshot("testsuite");
+}
+
+
+void
+second_snapshot()
+{
+ second = sh->createPostSnapshot(first);
+}
+
+
+void
+rollback()
+{
+ sh->setComparison(first, second);
+
+ Files& files = sh->getFiles();
+ for (Files::iterator it = files.begin(); it != files.end(); ++it)
+ it->setRollback(true);
+
+ sh->doRollback();
+}
+
+
+void
+check_first()
+{
+ Snapshots::const_iterator current = sh->getSnapshotCurrent();
+
+ sh->setComparison(first, current);
+
+ const Files& files = sh->getFiles();
+ for (Files::const_iterator it = files.begin(); it != files.end(); ++it)
+ cout << *it << endl;
+
+ check_true(files.empty());
+}
+
+
+void
+run_command(const char* command)
+{
+ string tmp = string("cd " ROOTDIR " ; ") + command;
+ check_zero(system(tmp.c_str()));
+}
--- /dev/null
+
+#include <string>
+
+using namespace std;
+
+
+template <typename Type> void
+check_failure(const char* str, Type actual, Type expected, const char* file,
+ int line, const char* func)
+{
+ std::cerr << file << ":" << line << ": \"" << func << "\"" << std::endl;
+ std::cerr << "check \"" << str << "\"" << " failed. expected " << expected
+ << ", actual " << actual << "." << std::endl;
+
+ exit(EXIT_FAILURE);
+}
+
+
+#define check_true(expr) \
+ do { \
+ bool actual = (expr); \
+ if (!actual) \
+ check_failure(#expr, actual, true, __FILE__, __LINE__, \
+ __PRETTY_FUNCTION__); \
+ } while (0)
+
+
+#define check_zero(expr) \
+ do { \
+ int actual = (expr); \
+ if (actual != 0) \
+ check_failure(#expr, actual, 0, __FILE__, __LINE__, \
+ __PRETTY_FUNCTION__); \
+ } while (0)
+
+
+void setup();
+void first_snapshot();
+void second_snapshot();
+void rollback();
+void check_first();
+
+void run_command(const char* command);
+
--- /dev/null
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+ setup();
+
+ run_command("mkdir directory");
+ run_command("chown nobody directory");
+
+ run_command("echo test > file");
+ run_command("chown nobody file");
+
+ run_command("ln --symbolic test link");
+ run_command("chown --no-dereference nobody link");
+
+ first_snapshot();
+
+ run_command("rmdir directory");
+ run_command("rm file");
+ run_command("rm link");
+
+ second_snapshot();
+
+ rollback();
+
+ check_first();
+
+ exit(EXIT_SUCCESS);
+}
--- /dev/null
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+ setup();
+
+ run_command("mkdir --mode a=rwx directory1");
+ run_command("mkdir --mode a=--- directory2");
+
+ run_command("echo test > file1");
+ run_command("chmod a=rwx file1");
+ run_command("echo test > file2");
+ run_command("chmod a=--- file2");
+
+ first_snapshot();
+
+ run_command("rmdir directory1");
+ run_command("rmdir directory2");
+
+ run_command("rm file1");
+ run_command("rm file2");
+
+ second_snapshot();
+
+ rollback();
+
+ check_first();
+
+ exit(EXIT_SUCCESS);
+}
--- /dev/null
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+ setup();
+
+ run_command("mkdir directory-pre");
+ run_command("echo test > file-pre");
+ run_command("ln --symbolic test link-pre");
+
+ first_snapshot();
+
+ run_command("rmdir directory-pre");
+ run_command("rm file-pre");
+ run_command("rm link-pre");
+
+ run_command("mkdir directory-post");
+ run_command("echo test > file-post");
+ run_command("ln --symbolic test link-post");
+
+ second_snapshot();
+
+ rollback();
+
+ check_first();
+
+ exit(EXIT_SUCCESS);
+}