Loading...
Searching...
No Matches
i_database.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef I_DATABASE_HPP
#define I_DATABASE_HPP
#include "../my_config.h"
#include <list>
#include "archive.hpp"
#include "generic_file.hpp"
#include "data_dir.hpp"
#include "storage.hpp"
#include "mem_ui.hpp"
#include "database_options.hpp"
#include "database_archives.hpp"
#include "database.hpp"
#include "tools.hpp"
#include "datetime.hpp"
#include "archive_options.hpp"
namespace libdar
{
class database::i_database: public mem_ui
{
public:
i_database(const std::shared_ptr<user_interaction> & dialog);
i_database(const std::shared_ptr<user_interaction> & dialog,
const std::string & base,
const database_open_options & opt);
i_database(const i_database & ref) = delete;
i_database(i_database && ref) noexcept = delete;
i_database & operator = (const i_database & ref) = delete;
i_database & operator = (i_database && ref) noexcept = delete;
~i_database();
void dump(const std::string & filename, const database_dump_options & opt) const;
// SETTINGS
void add_archive(const archive & arch, const std::string & chemin, const std::string & basename, const database_add_options & opt);
void remove_archive(archive_num min, archive_num max, const database_remove_options & opt);
void set_permutation(archive_num src, archive_num dst);
void change_name(archive_num num, const std::string & basename, const database_change_basename_options &opt);
void set_path(archive_num num, const std::string & chemin, const database_change_path_options & opt);
void set_options(const std::vector<std::string> &opt) { options_to_dar = opt; };
void set_dar_path(const std::string & chemin) { dar_path = chemin; };
void set_compression(compression algozip) const { algo = algozip; };
void set_compression_level(U_I level) const { compr_level = level; };
//
// "GETTINGS"
//
database_archives_list get_contents() const;
std::vector<std::string> get_options() const { return options_to_dar; }; // show option passed to dar
std::string get_dar_path() const { return dar_path; }; // show path to dar command
compression get_compression() const { return algo; };
U_I get_compression_level() const { return compr_level; };
std::string get_database_version() const { return tools_uint2str(cur_db_version); };
void get_files(database_listing_show_files_callback callback,
void *context,
archive_num num,
const database_used_options & opt) const;
void get_version(database_listing_get_version_callback callback,
void *context,
path chemin) const;
void show_most_recent_stats(database_listing_statistics_callback callback,
void *context) const;
// "ACTIONS" (not available with partially extracted databases)
void restore(const std::vector<std::string> & filename,
const database_restore_options & opt);
void restore(const archive_options_read & read_options,
const path & fs_root,
archive_options_extract extract_options,
const database_restore_options & opt,
statistics* progressive_report);
bool check_order() const
{
bool initial_warn = true;
if(files == nullptr)
throw SRC_BUG;
if(check_order_asked)
return files->check_order(get_ui(), path("."), initial_warn) && initial_warn;
else
return true;
}
private:
struct archive_data
{
std::string chemin;
std::string basename;
datetime root_last_mod;
};
std::deque<struct archive_data> coordinate;
std::vector<std::string> options_to_dar;
std::string dar_path;
data_dir *files;
storage *data_files;
bool check_order_asked;
unsigned char cur_db_version;
mutable compression algo;
mutable U_I compr_level;
void build(generic_file & f, bool partial, bool read_only, unsigned char db_version);
archive_num get_real_archive_num(archive_num num, bool revert) const;
const datetime & get_root_last_mod(const archive_num & num) const;
};
} // end of namespace
#endif
archive.hpp
the archive class is defined in this module
archive_options.hpp
this file contains a set of classes used to transmit options to archive operation
libdar::archive_num
class archive_num stores the position of an archive inside a dar_manager database
Definition archive_num.hpp:47
libdar::archive_options_extract
class holding optional parameters used to extract files from an existing archive
Definition archive_options.hpp:1351
libdar::archive_options_read
class holding optional parameters used to read an existing archive
Definition archive_options.hpp:70
libdar::archive
the archive class realizes the most general operations on archives
Definition archive.hpp:68
libdar::data_dir
the data_dir class inherits from data_tree and holds the directory tree's parent relationship
Definition data_dir.hpp:53
libdar::database::i_database
the class i_database is the implementation of class database
Definition i_database.hpp:55
libdar::database::i_database::files
data_dir * files
structure containing files and their status in the set of archive used for that database (is set to n...
Definition i_database.hpp:191
libdar::database::i_database::algo
compression algo
compression used/to use when writing down the base to file
Definition i_database.hpp:195
libdar::database::i_database::check_order_asked
bool check_order_asked
whether order check has been asked
Definition i_database.hpp:193
libdar::database::i_database::get_dar_path
std::string get_dar_path() const
returns the path for dar
Definition i_database.hpp:124
libdar::database::i_database::get_compression
compression get_compression() const
returns the compression algorithm used on filesystem
Definition i_database.hpp:127
libdar::database::i_database::cur_db_version
unsigned char cur_db_version
current db version (for informational purposes)
Definition i_database.hpp:194
libdar::database::i_database::i_database
i_database(i_database &&ref) noexcept=delete
disabling move constructor
libdar::database::i_database::build
void build(generic_file &f, bool partial, bool read_only, unsigned char db_version)
used by constructors
libdar::database::i_database::options_to_dar
std::vector< std::string > options_to_dar
options to use when calling dar for restoration
Definition i_database.hpp:189
libdar::database::i_database::remove_archive
void remove_archive(archive_num min, archive_num max, const database_remove_options &opt)
remove an archive from a database
libdar::database::i_database::set_permutation
void set_permutation(archive_num src, archive_num dst)
change order of archive within the database
libdar::database::i_database::operator=
i_database & operator=(const i_database &ref)=delete
disabling assignement operator
libdar::database::i_database::set_path
void set_path(archive_num num, const std::string &chemin, const database_change_path_options &opt)
change one's archive path recorded in the database
libdar::database::i_database::restore
void restore(const std::vector< std::string > &filename, const database_restore_options &opt)
restore files calling dar on the appropriated archive
libdar::database::i_database::get_files
void get_files(database_listing_show_files_callback callback, void *context, archive_num num, const database_used_options &opt) const
list files which are present in a given archive
libdar::database::i_database::check_order
bool check_order() const
check that all files's Data and EA are more recent when archive number grows within the database,...
Definition i_database.hpp:165
libdar::database::i_database::show_most_recent_stats
void show_most_recent_stats(database_listing_statistics_callback callback, void *context) const
compute some statistics about the location of most recent file versions
libdar::database::i_database::data_files
storage * data_files
when reading archive in partial mode, this is where is located the "not readed" part of the archive (...
Definition i_database.hpp:192
libdar::database::i_database::i_database
i_database(const i_database &ref)=delete
disabling copy constructor
libdar::database::i_database::dar_path
std::string dar_path
path to dar
Definition i_database.hpp:190
libdar::database::i_database::compr_level
U_I compr_level
the compression level to use
Definition i_database.hpp:196
libdar::database::i_database::i_database
i_database(const std::shared_ptr< user_interaction > &dialog, const std::string &base, const database_open_options &opt)
this constructor reads i_database from a file
libdar::database::i_database::get_compression_level
U_I get_compression_level() const
returns the compression level used on file
Definition i_database.hpp:130
libdar::database::i_database::coordinate
std::deque< struct archive_data > coordinate
list of archive used to build the database
Definition i_database.hpp:188
libdar::database::i_database::set_compression_level
void set_compression_level(U_I level) const
change the compression level to use when storing base in file
Definition i_database.hpp:110
libdar::database::i_database::~i_database
~i_database()
i_database destructor (no implicit file saving)
libdar::database::i_database::set_compression
void set_compression(compression algozip) const
change compression to use when storing base on file
Definition i_database.hpp:107
libdar::database::i_database::get_contents
database_archives_list get_contents() const
provides the list of archive used to build the database
libdar::database::i_database::get_options
std::vector< std::string > get_options() const
return the options used with dar for restoration
Definition i_database.hpp:121
libdar::database::i_database::restore
void restore(const archive_options_read &read_options, const path &fs_root, archive_options_extract extract_options, const database_restore_options &opt, statistics *progressive_report)
restore files calling libdar directly rather than spawning dar CLI and parsing options as CLI
libdar::database::i_database::change_name
void change_name(archive_num num, const std::string &basename, const database_change_basename_options &opt)
change one's archive basename recorded in the database
libdar::database::i_database::get_version
void get_version(database_listing_get_version_callback callback, void *context, path chemin) const
list the archive where a give file is present
libdar::database::i_database::dump
void dump(const std::string &filename, const database_dump_options &opt) const
write the database to a file (see database_header first)
libdar::database::i_database::get_database_version
std::string get_database_version() const
return the database format version
Definition i_database.hpp:133
libdar::database::i_database::set_dar_path
void set_dar_path(const std::string &chemin)
change the path to dar command
Definition i_database.hpp:104
libdar::database::i_database::i_database
i_database(const std::shared_ptr< user_interaction > &dialog)
this constructor build an empty database
libdar::database::i_database::add_archive
void add_archive(const archive &arch, const std::string &chemin, const std::string &basename, const database_add_options &opt)
add an archive to the database
libdar::database::i_database::set_options
void set_options(const std::vector< std::string > &opt)
change the default options given to dar when performing restoration
Definition i_database.hpp:101
libdar::database_add_options
options to add an archive to base
Definition database_options.hpp:133
libdar::database_change_basename_options
options for changing a given archive's basename
Definition database_options.hpp:172
libdar::database_change_path_options
options for changing a given archive's path
Definition database_options.hpp:197
libdar::database_dump_options
options to write a database to file
Definition database_options.hpp:103
libdar::database_open_options
options to open a database
Definition database_options.hpp:54
libdar::database_remove_options
options to remove an archive from the base
Definition database_options.hpp:148
libdar::database_restore_options
options for restoration from database
Definition database_options.hpp:221
libdar::database_used_options
options for file "used" in archive
Definition database_options.hpp:294
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::mem_ui::mem_ui
mem_ui(const std::shared_ptr< user_interaction > &dialog)
constructor
libdar::mem_ui::get_ui
user_interaction & get_ui() const
get access to the user_interaction object
Definition mem_ui.hpp:94
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition path.hpp:51
libdar::statistics
class used by libdar::archive class to give a summary of treated file during and after an operation
Definition statistics.hpp:70
libdar::storage
arbitrary large storage structure
Definition storage.hpp:53
data_dir.hpp
classes used to store directory tree information in dar_manager databases
database.hpp
this file holds the database class definition
database_archives.hpp
this file stores the list of archives a database has been built from. it is part of the database head...
database_options.hpp
this file holds the options for database operations
datetime.hpp
this file contains the definition of class datetime that stores unix times in a portable way
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::database_listing_get_version_callback
void(*)(void *context, archive_num num, db_etat data_presence, bool has_data_date, datetime data, db_etat ea_presence, bool has_ea_date, datetime ea) database_listing_get_version_callback
called with the information of presence for an entry in archive number num
Definition database_listing_callback.hpp:63
libdar::database_archives_list
std::deque< database_archives > database_archives_list
list of archives found in a database
Definition database_archives.hpp:75
libdar::database_listing_statistics_callback
void(*)(void *context, U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea) database_listing_statistics_callback
called with teh information of statistics for each archive in turn
Definition database_listing_callback.hpp:81
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
libdar::database_listing_show_files_callback
void(*)(void *context, const std::string &filename, bool available_data, bool available_ea) database_listing_show_files_callback
called by the database::get_files() routine
Definition database_listing_callback.hpp:48
libdar::ea_saved_status::partial
@ partial
EA present in filesystem but not stored (ctime used to check changes).
Definition cat_status.hpp:57
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
storage.hpp
contains a class that permits arbitrary large data storage
libdar::database::i_database::archive_data
holds the archive used to create the database
Definition i_database.hpp:182
libdar::database::i_database::archive_data::chemin
std::string chemin
path to the archive
Definition i_database.hpp:183
libdar::database::i_database::archive_data::root_last_mod
datetime root_last_mod
last modification date of the root directory
Definition i_database.hpp:185
libdar::database::i_database::archive_data::basename
std::string basename
basename of the archive
Definition i_database.hpp:184
tools.hpp
a set of general purpose routines