Joedb
9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
src
joedb
journal
SFTP_File.h
Go to the documentation of this file.
1
#ifndef joedb_SFTP_File_declared
2
#define joedb_SFTP_File_declared
3
4
#include "
joedb/journal/Buffered_File.h
"
5
#include "
joedb/ssh/SFTP.h
"
6
7
#include <fcntl.h>
8
9
namespace
joedb
10
{
11
/// @ingroup journal
12
class
SFTP_File
:
public
Buffered_File
13
{
14
private
:
15
ssh::SFTP
&sftp;
16
const
sftp_file file;
17
18
void
throw_last_error(
const
char
*action,
const
char
*file_name)
const
19
{
20
sftp.
throw_error
21
(
22
(std::string(action) +
' '
+ std::string(file_name) +
": "
).c_str()
23
);
24
}
25
26
mutable
int64_t pos;
27
28
void
seek(int64_t offset)
const
29
{
30
if
(offset == pos)
31
return
;
32
33
if
(sftp_seek64(file, uint64_t(offset)) < 0)
34
throw_last_error(
"seeking in"
,
"sftp file"
);
35
36
pos = offset;
37
}
38
39
public
:
40
SFTP_File
(
ssh::SFTP
&sftp,
const
char
*file_name):
41
Buffered_File
(
Open_Mode
::
read_existing
),
42
sftp(sftp),
43
file(sftp_open(sftp.get(), file_name, O_RDONLY, 0))
44
{
45
if
(!file)
46
throw_last_error(
"opening"
, file_name);
47
}
48
49
SFTP_File
(
const
SFTP_File
&) =
delete
;
50
SFTP_File
&
operator=
(
const
SFTP_File
&) =
delete
;
51
52
size_t
pread
(
char
*data,
size_t
size, int64_t offset)
const override
53
{
54
seek(offset);
55
56
const
ssize_t result = sftp_read(file, data, size);
57
58
if
(result < 0)
59
throw_last_error(
"reading"
,
"sftp file"
);
60
61
pos += result;
62
return
size_t(result);
63
}
64
65
~SFTP_File
()
override
66
{
67
sftp_close(file);
68
}
69
};
70
}
71
72
#endif
Buffered_File.h
SFTP.h
joedb::Buffered_File
Definition
Buffered_File.h:18
joedb::SFTP_File
Definition
SFTP_File.h:13
joedb::SFTP_File::operator=
SFTP_File & operator=(const SFTP_File &)=delete
joedb::SFTP_File::SFTP_File
SFTP_File(const SFTP_File &)=delete
joedb::SFTP_File::pread
size_t pread(char *data, size_t size, int64_t offset) const override
Read a range of bytes.
Definition
SFTP_File.h:52
joedb::SFTP_File::~SFTP_File
~SFTP_File() override
Definition
SFTP_File.h:65
joedb::SFTP_File::SFTP_File
SFTP_File(ssh::SFTP &sftp, const char *file_name)
Definition
SFTP_File.h:40
joedb::ssh::SFTP_Allocation::throw_error
void throw_error(const char *message="sftp error: ") const
Definition
SFTP.cpp:28
joedb::ssh::SFTP
Definition
SFTP.h:50
joedb::Open_Mode
Open_Mode
Definition
Open_Mode.h:8
joedb::Open_Mode::read_existing
@ read_existing
fails if does not exist
joedb
Definition
Blob.h:7
Generated by
1.9.8