Disk ARchive  2.4.8
 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 
25 
26 
27 #ifndef DATABASE_HPP
28 #define DATABASE_HPP
29 
30 #include "../my_config.h"
31 
32 #include <list>
33 
34 #include "archive.hpp"
35 #include "generic_file.hpp"
36 #include "data_tree.hpp"
37 #include "storage.hpp"
38 #include "database_options.hpp"
39 
40 namespace libdar
41 {
43 
48  class database
49  {
50  public:
52  database();
53 
55 
59  database(user_interaction & dialog, const std::string & base, const database_open_options & opt);
60 
62  ~database();
63 
65 
69  void dump(user_interaction & dialog, const std::string & filename, const database_dump_options & opt) const;
70 
71  // SETTINGS
72 
74 
80  void add_archive(const archive & arch, const std::string & chemin, const std::string & basename, const database_add_options & opt);
81 
83 
91 
93 
98 
100 
104  void change_name(archive_num num, const std::string & basename, const database_change_basename_options &opt);
105 
107 
111  void set_path(archive_num num, const std::string & chemin, const database_change_path_options & opt);
112 
114 
119  void set_options(const std::vector<std::string> &opt) { options_to_dar = opt; };
120 
122 
125  void set_dar_path(const std::string & chemin) { dar_path = chemin; };
126 
127 
128  // "GETTINGS"
129 
131 
134  void show_contents(user_interaction & dialog) const; // displays all archive information
135 
137  std::vector<std::string> get_options() const { return options_to_dar; }; // show option passed to dar
138 
140 
143  std::string get_dar_path() const { return dar_path; }; // show path to dar command
144 
146 
152  void show_files(user_interaction & dialog, archive_num num, const database_used_options & opt) const;
153 
155 
159  void show_version(user_interaction & dialog, path chemin) const;
160 
162 
165  void show_most_recent_stats(user_interaction & dialog) const;
166 
167  // "ACTIONS" (not available with partially extracted databases)
168 
170 
174  void restore(user_interaction & dialog,
175  const std::vector<std::string> & filename,
176  const database_restore_options & opt);
177 
179 
182 
183  bool check_order(user_interaction & dialog) const
184  {
185  bool initial_warn = true;
186 
187  if(files == NULL)
188  throw SRC_BUG;
189  if(check_order_asked)
190  return files->check_order(dialog, ".", initial_warn) && initial_warn;
191  else
192  return true;
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  infinint root_last_mod; //< last modification date of the root directory
204  };
205 
206  std::vector<struct archive_data> coordinate; //< list of archive used to build the database
207  std::vector<std::string> options_to_dar; //< options to use when calling dar for restoration
208  std::string dar_path; //< path to dar
209  data_dir *files; //< structure containing files and their status in the set of archive used for that database (is set to NULL in partial mode)
210  storage *data_files; //< when reading archive in partial mode, this is where is located the "not readed" part of the archive (is set to NULL in partial-read-only mode)
211  bool check_order_asked; //< whether order check has been asked
212 
213  void build(user_interaction & dialog, generic_file & f, bool partial, bool read_only, unsigned char db_version); //< used by constructors
214  archive_num get_real_archive_num(archive_num num, bool revert) const;
215 
216  const infinint & get_root_last_mod(const archive_num & num) const;
217  };
218 
219 } // end of namespace
220 
221 #endif