Loading...
Searching...
No Matches
fichier_libssh.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 FICHIER_LIBSSH_HPP
#define FICHIER_LIBSSH_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
} // end extern "C"
#include "integers.hpp"
#include "user_interaction.hpp"
#include "fichier_global.hpp"
#include "libssh_connection.hpp"
#include "cygwin_adapt.hpp"
#include <string>
namespace libdar
{
#if LIBSSH_AVAILABLE
class fichier_libssh : public fichier_global
{
public:
fichier_libssh(const std::shared_ptr<user_interaction> & dialog,
const std::shared_ptr<libssh_connection> & ptr,
const std::string & chemin,
gf_mode mode,
U_I permission,
bool fail_if_exists,
bool erase);
fichier_libssh(const fichier_libssh & ref) = delete;
fichier_libssh(fichier_libssh && ref) noexcept = delete;
fichier_libssh & operator = (const fichier_libssh & ref) = delete;
fichier_libssh & operator = (fichier_libssh && ref) noexcept = delete;
~fichier_libssh();
virtual void change_ownership(const std::string & user, const std::string & group) override
{ throw Efeature(gettext("user/group ownership not implemented for this repository")); };
// not implemented, libssh can set ownership based on uid / gid but not based on user/group names
virtual void change_permission(U_I perm) override;
virtual infinint get_size() const override;
virtual void fadvise(advise adv) const override {}; // not supported
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override;
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override;
virtual infinint get_position() const override;
protected:
// inherited from generic_file grand-parent class
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_read_ahead(const infinint & amount) override;
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override { myclose(); };
// inherited from fichier_global parent class
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override;
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) override;
private:
std::shared_ptr<libssh_connection> connect;
std::string my_path;
sftp_file sfd;
infinint current_pos;
// read ahead structures
struct rahead
{
sftp_aio handle;
rahead(): handle(nullptr) {};
rahead(const rahead & ref) = delete;
rahead(rahead && ref) noexcept { handle = ref.handle; ref.handle = nullptr; };
rahead & operator = (const rahead & ref) = delete;
rahead & operator = (rahead && ref) noexcept { std::swap(handle, ref.handle); return *this; };
~rahead() { if(handle != nullptr) sftp_aio_free(handle); };
};
static const U_I read_ahead_window_size = 100*1024*1024;
infinint tora;
std::deque<rahead> rareq;
U_I rareq_maxsize;
char* rabuffer;
U_I rallocated;
U_I rasize;
U_I ralu;
// private methods
void myclose();
void clear_readahead() { rareq.clear(); ralu = rasize = 0; };
void update_aio_reqs();
void check_pos_from_libssh();
};
#endif
} // end of namespace
#endif
libdar::fichier_global
abstraction of filesystem files for entrepot
Definition fichier_global.hpp:59
cygwin_adapt.hpp
thin C++ adaptation layer to Cygwin specifities
fichier_global.hpp
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
integers.hpp
are defined here basic integer types that tend to be portable
libssh_connection.hpp
class holding libssh related data structure for an ssh and sftp session
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
user_interaction.hpp
defines the interaction interface between libdar and users.