{
snapshots.assertInit();
- for (vector<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
+ for (list<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
{
cout << *it << endl;
}
using namespace std;
-/*
- void
- listSnapshots()
- {
- assertInit();
-
- for (list<Snapshot>::const_iterator it = snapshots.begin();
- it != snapshots.end(); ++it)
- {
- cout << *it << endl;
- }
- }
-*/
-
-
void
- startBackgroundComparsion(unsigned int num1, unsigned int num2)
+ startBackgroundComparsion(list<Snapshot>::const_iterator snapshot1,
+ list<Snapshot>::const_iterator snapshot2)
{
- y2mil("num1:" << num1 << " num2:" << num2);
+ y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
- string dir1 = SNAPSHOTSDIR "/" + decString(num1) + "/snapshot";
- string dir2 = SNAPSHOTSDIR "/" + decString(num2) + "/snapshot";
+ string dir1 = snapshot1->snapshotDir();
+ string dir2 = snapshot2->snapshotDir();
- string output = SNAPSHOTSDIR "/" + decString(num2) + "/filelist-" + decString(num1) + ".txt";
+ string output = snapshot2->baseDir() + "/filelist-" + decString(snapshot1->getNum()) +
+ ".txt";
SystemCmd(COMPAREDIRSBIN " " + quote(dir1) + " " + quote(dir2) + " " + quote(output));
}
bool
- setComparisonNums(unsigned int num1, unsigned int num2)
+ setComparisonNums(list<Snapshot>::const_iterator new_snapshot1,
+ list<Snapshot>::const_iterator new_snapshot2)
{
- y2mil("num1:" << num1 << " num2:" << num2);
-
- snapshots.assertInit();
+ y2mil("num1:" << new_snapshot1->getNum() << " num2:" << new_snapshot2->getNum());
- snapshot1 = snapshots.find(num1);
- if (snapshot1 == snapshots.end())
- return false;
-
- snapshot2 = snapshots.find(num2);
- if (snapshot2 == snapshots.end())
- return false;
+ snapshot1 = new_snapshot1;
+ snapshot2 = new_snapshot2;
files.assertInit();
}
-/*
- list<string>
- getFiles()
- {
- filelist.assertInit();
-
- list<string> ret;
- for (vector<File>::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
- ret.push_back(it->name);
-
- return ret;
- }
-*/
-
-
- unsigned int
- getStatus(const string& name, Cmp cmp)
- {
- vector<File>::iterator it = files.find(name);
- if (it != files.end())
- return it->getStatus(cmp);
-
- return -1;
- }
-
-
- void
- setRollback(const string& name, bool rollback)
- {
- vector<File>::iterator it = files.find(name);
- if (it != files.end())
- it->setRollback(rollback);
- }
-
-
- bool
- getRollback(const string& name, bool rollback)
- {
- vector<File>::const_iterator it = files.find(name);
- if (it != files.end())
- return it->getRollback();
- return false;
- }
-
-
CompareCallback* compare_callback = NULL;
void
#include <string>
+#include <list>
namespace snapper
{
- using std::string;
+ using namespace std;
enum StatusFlags
};
- // use num = 0 for current system
+ class Snapshot;
- void startBackgroundComparsion(unsigned int num1, unsigned int num2);
+ void startBackgroundComparsion(list<Snapshot>::const_iterator snapshot1,
+ list<Snapshot>::const_iterator snapshot2);
- bool setComparisonNums(unsigned int num1, unsigned int num2);
-
- unsigned int getComparisonNum1();
- unsigned int getComparisonNum2();
-
-
- // return bitfield of StatusFlags
- unsigned int getStatus(const string& name, Cmp cmp);
-
- string getAbsolutePath(const string& name, Location loc);
-
- void setRollback(const string& name, bool rollback);
- bool getRollback(const string& name);
-
- // check rollback? (e.g. to be deleted dirs are empty, required type changes)
- bool checkRollback();
-
- bool doRollback();
+ bool setComparisonNums(list<Snapshot>::const_iterator snapshot1,
+ list<Snapshot>::const_iterator snapshot2);
// progress callbacks, e.g. during snapshot comparision, during rollback,
using std::list;
- vector<Snapshot>::const_iterator snapshot1;
- vector<Snapshot>::const_iterator snapshot2;
+ list<Snapshot>::const_iterator snapshot1;
+ list<Snapshot>::const_iterator snapshot2;
Snapshots snapshots;
entries.push_back(snapshot);
}
- sort(entries.begin(), entries.end());
+ entries.sort();
y2mil("found " << entries.size() << " snapshots");
}
}
- vector<Snapshot>::iterator
+ list<Snapshot>::iterator
Snapshots::find(unsigned int num)
{
return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less);
}
- vector<Snapshot>::const_iterator
+ list<Snapshot>::const_iterator
Snapshots::find(unsigned int num) const
{
return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less);
#define SNAPSHOT_H
-#include <vector>
+#include <list>
namespace snapper
}
- extern vector<Snapshot>::const_iterator snapshot1;
- extern vector<Snapshot>::const_iterator snapshot2;
+ extern list<Snapshot>::const_iterator snapshot1;
+ extern list<Snapshot>::const_iterator snapshot2;
class Snapshots
void assertInit();
- vector<Snapshot>::const_iterator begin() const { return entries.begin(); }
- vector<Snapshot>::const_iterator end() const { return entries.end(); }
+ list<Snapshot>::const_iterator begin() const { return entries.begin(); }
+ list<Snapshot>::const_iterator end() const { return entries.end(); }
- vector<Snapshot>::iterator find(unsigned int num);
- vector<Snapshot>::const_iterator find(unsigned int num) const;
+ list<Snapshot>::iterator find(unsigned int num);
+ list<Snapshot>::const_iterator find(unsigned int num) const;
unsigned int createSingleSnapshot(string description);
unsigned int createPreSnapshot(string description);
bool initialized;
- vector<Snapshot> entries;
+ list<Snapshot> entries;
};
{
snapshots.assertInit();
- for (vector<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
+ for (list<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
{
cout << *it << endl;
}
unsigned int number2 = snapshots.createPostSnapshot(number1);
if (print_number)
cout << number2 << endl;
- startBackgroundComparsion(number1, number2);
+ startBackgroundComparsion(snapshots.find(number1), snapshots.find(number2));
}
else
y2war( "unknown type:\"" << type << "\"" );
readNums(args, num1, num2);
- setComparisonNums(num1, num2);
+ setComparisonNums(snapshots.find(num1), snapshots.find(num2));
for (vector<File>::const_iterator it = files.begin(); it != files.end(); ++it)
cout << statusToString(it->getPreToPostStatus()) << " " << it->getName() << endl;
readNums(args, num1, num2);
- setComparisonNums(num1, num2);
+ setComparisonNums(snapshots.find(num1), snapshots.find(num2));
for (vector<File>::iterator it = files.begin(); it != files.end(); ++it)
it->setRollback(true);
setCompareCallback(&compare_callback_impl);
+ snapshots.assertInit();
+
int cnt = optind;
while( cnt<argc )
{