The map::at method does not always exist, so instead use map::find.
[cumulus.git] / metadata.h
1 /* Cumulus: Smart Filesystem Backup to Dumb Servers
2  *
3  * Copyright (C) 2007-2008  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 /* Handling of metadata written to backup snapshots.  This manages the writing
22  * of file metadata into new backup snapshots, including breaking the metadata
23  * log apart across separate objects.  Eventually this should include unified
24  * handling of the statcache, and re-use of metadata between snapshots.
25  */
26
27 #ifndef _LBS_METADATA_H
28 #define _LBS_METADATA_H
29
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <list>
34 #include <string>
35 #include <sstream>
36
37 #include "store.h"
38 #include "ref.h"
39 #include "util.h"
40
41 extern bool flag_full_metadata;
42
43 /* Metadata for a single inode, ready to be written out. */
44 struct MetadataItem {
45     int offset;
46     std::string text;
47
48     bool reused;
49     ObjectReference ref;
50 };
51
52 class MetadataWriter {
53 public:
54     MetadataWriter(TarSegmentStore *store, const char *path,
55                    const char *snapshot_name, const char *snapshot_scheme);
56     void add(dictionary info);
57     ObjectReference close();
58
59     bool find(const std::string& path);
60     ObjectReference old_ref() const {
61         return ObjectReference::parse(old_metadata_loc);
62     }
63
64     bool is_unchanged(const struct stat *stat_buf);
65
66     dictionary get_old_metadata() const { return old_metadata; }
67     std::list<ObjectReference> get_blocks();
68     std::string get_checksum() { return old_metadata["checksum"]; }
69
70 private:
71     void metadata_flush();
72     void read_statcache();
73
74     // Where are objects eventually written to?
75     TarSegmentStore *store;
76
77     // File descriptors for reading/writing local statcache data
78     std::string statcache_path, statcache_tmp_path;
79     FILE *statcache_in, *statcache_out;
80
81     // Metadata not yet written out to the segment store
82     size_t chunk_size;
83     std::list<MetadataItem> items;
84     std::ostringstream metadata_root;
85
86     // Statcache information read back in from a previous run
87     bool old_metadata_eof;
88     dictionary old_metadata;
89     std::string old_metadata_loc;   // Reference to where the metadata is found
90 };
91
92 #endif // _LBS_METADATA_H