summaryrefslogtreecommitdiff
path: root/lib/db_file.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/db_file.h')
-rw-r--r--lib/db_file.h68
1 files changed, 63 insertions, 5 deletions
diff --git a/lib/db_file.h b/lib/db_file.h
index e5ae7b50..4425f52c 100644
--- a/lib/db_file.h
+++ b/lib/db_file.h
@@ -14,17 +14,75 @@ namespace zen
{
const Zstring SYNC_DB_FILE_ENDING = Zstr(".ffs_db");
-struct DirInformation
+//artificial hierarchy of last synchronous state:
+struct InSyncFile
{
- DirContainer baseDirContainer; //hierarchical directory information
+ enum InSyncType
+ {
+ IN_SYNC_BINARY_EQUAL, //checked file content
+ IN_SYNC_ATTRIBUTES_EQUAL, //only "looks" like they're equal
+ };
+
+ InSyncFile(const FileDescriptor& l, const FileDescriptor& r, InSyncType type) : left(l), right(r), inSyncType(type) {}
+ FileDescriptor left;
+ FileDescriptor right;
+ InSyncType inSyncType;
+};
+
+struct InSyncSymlink
+{
+ InSyncSymlink(const LinkDescriptor& l, const LinkDescriptor& r) : left(l), right(r) {}
+ LinkDescriptor left;
+ LinkDescriptor right;
+};
+
+struct InSyncDir
+{
+ //for directories we have a logical problem: we cannot have "not existent" as an indicator for "no last synchronous state" since this precludes
+ //child elements that may be in sync!
+ enum InSyncStatus
+ {
+ STATUS_IN_SYNC,
+ STATUS_STRAW_MAN //there is no last synchronous state, but used as container only
+ };
+ InSyncDir(InSyncStatus statusIn) : status(statusIn) {}
+
+ InSyncStatus status;
+
+ //------------------------------------------------------------------
+ typedef std::map<Zstring, InSyncDir, LessFilename> DirList; //
+ typedef std::map<Zstring, InSyncFile, LessFilename> FileList; // key: shortName
+ typedef std::map<Zstring, InSyncSymlink, LessFilename> LinkList; //
+ //------------------------------------------------------------------
+
+ DirList dirs;
+ FileList files;
+ LinkList symlinks; //non-followed symlinks
+
+ //convenience
+ InSyncDir& addDir(const Zstring& shortName, InSyncStatus statusIn)
+ {
+ //use C++11 emplace when available
+ return dirs.insert(std::make_pair(shortName, InSyncDir(statusIn))).first->second;
+ }
+
+ void addFile(const Zstring& shortName, const FileDescriptor& dataL, const FileDescriptor& dataR, InSyncFile::InSyncType type)
+ {
+ files.insert(std::make_pair(shortName, InSyncFile(dataL, dataR, type)));
+ }
+
+ void addSymlink(const Zstring& shortName, const LinkDescriptor& dataL, const LinkDescriptor& dataR)
+ {
+ symlinks.insert(std::make_pair(shortName, InSyncSymlink(dataL, dataR)));
+ }
};
-typedef std::shared_ptr<const DirInformation> DirInfoPtr;
+
DEFINE_NEW_FILE_ERROR(FileErrorDatabaseNotExisting);
-std::pair<DirInfoPtr, DirInfoPtr> loadFromDisk(const BaseDirMapping& baseMapping); //throw FileError, FileErrorDatabaseNotExisting -> return value always bound!
+std::shared_ptr<InSyncDir> loadLastSynchronousState(const BaseDirMapping& baseMapping); //throw FileError, FileErrorDatabaseNotExisting -> return value always bound!
-void saveToDisk(const BaseDirMapping& baseMapping); //throw FileError
+void saveLastSynchronousState(const BaseDirMapping& baseMapping); //throw FileError
}
#endif // DBFILE_H_INCLUDED
bgstack15