Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
database.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: database.hpp,v 1.14 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 
30 #ifndef DATABASE_HPP
31 #define DATABASE_HPP
32 
33 #include "../my_config.h"
34 
35 #include <list>
36 
37 #include "archive.hpp"
38 #include "generic_file.hpp"
39 #include "data_tree.hpp"
40 #include "storage.hpp"
41 #include "database_options.hpp"
42 
43 namespace libdar
44 {
46 
51  class database
52  {
53  public:
55  database();
56 
58 
62  database(user_interaction & dialog, const std::string & base, const database_open_options & opt);
63 
65  ~database();
66 
68 
72  void dump(user_interaction & dialog, const std::string & filename, const database_dump_options & opt) const;
73 
74  // SETTINGS
75 
77 
83  void add_archive(const archive & arch, const std::string & chemin, const std::string & basename, const database_add_options & opt);
84 
86 
94 
96 
100  void set_permutation(archive_num src, archive_num dst);
101 
103 
107  void change_name(archive_num num, const std::string & basename, const database_change_basename_options &opt);
108 
110 
114  void set_path(archive_num num, const std::string & chemin, const database_change_path_options & opt);
115 
117 
122  void set_options(const std::vector<std::string> &opt) { options_to_dar = opt; };
123 
125 
128  void set_dar_path(const std::string & chemin) { dar_path = chemin; };
129 
130 
131  // "GETTINGS"
132 
134 
137  void show_contents(user_interaction & dialog) const; // displays all archive information
138 
140  std::vector<std::string> get_options() const { return options_to_dar; }; // show option passed to dar
141 
143 
146  std::string get_dar_path() const { return dar_path; }; // show path to dar command
147 
149 
155  void show_files(user_interaction & dialog, archive_num num, const database_used_options & opt) const;
156 
158 
162  void show_version(user_interaction & dialog, path chemin) const;
163 
165 
168  void show_most_recent_stats(user_interaction & dialog) const;
169 
170  // "ACTIONS" (not available with partially extracted databases)
171 
173 
177  void restore(user_interaction & dialog,
178  const std::vector<std::string> & filename,
179  const database_restore_options & opt);
180 
182 
185 
186  bool check_order(user_interaction & dialog) const
187  {
188  bool initial_warn = true;
189 
190  if(files == NULL)
191  throw SRC_BUG;
192  return files->check_order(dialog, ".", initial_warn) && initial_warn;
193  }
194 
195 
196  private:
197 
199  struct archive_data
200  {
201  std::string chemin; //< path to the archive
202  std::string basename; //< basename of the archive
203  };
204 
205  std::vector<struct archive_data> coordinate; //< list of archive used to build the database
206  std::vector<std::string> options_to_dar; //< options to use when calling dar for restoration
207  std::string dar_path; //< path to dar
208  data_dir *files; //< structure containing files and they status in the set of archive used for that database
209  storage *data_files; //< when reading archive in partial mode, this is where is located the "not readed" part of the archive
210 
211  void build(user_interaction & dialog, generic_file & f, bool partial, unsigned char db_version); //< used by constructors
212  archive_num get_real_archive_num(archive_num num, bool revert) const;
213  };
214 
215 } // end of namespace
216 
217 #endif