Disk ARchive: fichier_libssh.hpp Source File

| Disk ARchive 2.8.3 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
fichier_libssh.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
26
27#ifndef FICHIER_LIBSSH_HPP
28#define FICHIER_LIBSSH_HPP
29
30
31#include "../my_config.h"
32
33extern "C"
34{
35#if HAVE_UNISTD_H
36#include <unistd.h>
37#endif
38} // end extern "C"
39
40#include "integers.hpp"
41#include "user_interaction.hpp"
42#include "fichier_global.hpp"
43#include "libssh_connection.hpp"
44#include "cygwin_adapt.hpp"
45
46#include <string>
47
48namespace libdar
49{
50
53
54
56
57#if LIBSSH_AVAILABLE
58
59 class fichier_libssh : public fichier_global
60 {
61 public:
62
64 fichier_libssh(const std::shared_ptr<user_interaction> & dialog,
65 const std::shared_ptr<libssh_connection> & ptr,
66 const std::string & chemin,
67 gf_mode mode,
68 U_I permission,
69 bool fail_if_exists,
70 bool erase);
71
73 fichier_libssh(const fichier_libssh & ref) = delete;
74
76 fichier_libssh(fichier_libssh && ref) noexcept = delete;
77
79 fichier_libssh & operator = (const fichier_libssh & ref) = delete;
80
82 fichier_libssh & operator = (fichier_libssh && ref) noexcept = delete;
83
85 ~fichier_libssh();
86
87
89 virtual void change_ownership(const std::string & user, const std::string & group) override
90 { throw Efeature(gettext("user/group ownership not implemented for this repository")); };
91 // not implemented, libssh can set ownership based on uid / gid but not based on user/group names
92
94 virtual void change_permission(U_I perm) override;
95
97 virtual infinint get_size() const override;
98
100 virtual void fadvise(advise adv) const override {}; // not supported
101
102 // inherited from generic_file
103 virtual bool skippable(skippability direction, const infinint & amount) override;
104 virtual bool skip(const infinint & pos) override;
105 virtual bool skip_to_eof() override;
106 virtual bool skip_relative(S_I x) override;
107 virtual bool truncatable(const infinint & pos) const override;
108 virtual infinint get_position() const override;
109
110 protected:
111 // inherited from generic_file grand-parent class
112 virtual void inherited_truncate(const infinint & pos) override;
113 virtual void inherited_read_ahead(const infinint & amount) override;
114 virtual void inherited_sync_write() override {};
115 virtual void inherited_flush_read() override {};
116 virtual void inherited_terminate() override { myclose(); };
117
118 // inherited from fichier_global parent class
119 virtual U_I fichier_global_inherited_write(const char *a, U_I size) override;
120 virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) override;
121
122 private:
123 std::shared_ptr<libssh_connection> connect;
124 std::string my_path;
125 sftp_file sfd;
126 infinint current_pos;
127
128 // read ahead structures
129
130 struct rahead
131 {
132 sftp_aio handle;
133
134 rahead(): handle(nullptr) {};
135 rahead(const rahead & ref) = delete;
136 rahead(rahead && ref) noexcept { handle = ref.handle; ref.handle = nullptr; };
137 rahead & operator = (const rahead & ref) = delete;
138 rahead & operator = (rahead && ref) noexcept { std::swap(handle, ref.handle); return *this; };
139 ~rahead() { if(handle != nullptr) sftp_aio_free(handle); };
140 };
141
142 static const U_I read_ahead_window_size = 100*1024*1024;
144
145 infinint tora;
146
147 std::deque<rahead> rareq;
148 U_I rareq_maxsize;
149
150 char* rabuffer;
151 U_I rallocated;
152 U_I rasize;
153 U_I ralu;
154
155 // private methods
156
157 void myclose();
158 void clear_readahead() { rareq.clear(); ralu = rasize = 0; };
159 void update_aio_reqs();
160
162
166 void check_pos_from_libssh();
167
168 };
169
170#endif
171
173
174} // end of namespace
175
176#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.