ewmscp  ..
Public Member Functions | List of all members
inputHandler::libssh::readerLibssh Class Reference

#include <inputHandlerLibssh.h>

Inheritance diagram for inputHandler::libssh::readerLibssh:
[legend]
Collaboration diagram for inputHandler::libssh::readerLibssh:
[legend]

Public Member Functions

 readerLibssh (const std::string &aPath, libsshCommon &aHandler, copyRequest::stateType &state, const genericStat &inititalStat)
 
 ~readerLibssh () override
 
void seek (size_t pos) override
 
bool readBlock (block &b) override
 
void checkUnchangedness () override
 
- Public Member Functions inherited from libsshIoCommon
 libsshIoCommon (const std::string &aPath, libsshCommon &aHandler)
 
std::unique_ptr< const genericStatgetStat () override
 
- Public Member Functions inherited from ioHandle
 ioHandle ()
 
virtual ~ioHandle () noexcept(false)
 
virtual bool parallelizable () const
 tell if this handler is capable of parallel IO. Unsually not the case More...
 
virtual void setXattr (const std::string &, const std::string &)
 
virtual std::string getXattr (const std::string &)
 get one extended attribute value More...
 
virtual void removeXattr (const std::string &)
 
virtual size_t getBlockSize () const
 
virtual void setBlockSize (size_t newSize)
 
virtual std::unique_ptr< attrDataTypegetAttrData (const outputHandler::base *)
 get attributes in the optimal way for setting with aOutputHandler More...
 
virtual std::unique_ptr< acl::listgetAclData ()
 get acls More...
 

Additional Inherited Members

- Protected Attributes inherited from libsshIoCommon
libsshCommonhandler
 
const std::string path
 
sftp_file file
 
- Protected Attributes inherited from ioHandle
size_t blockSize
 in bytes, block size to be used when reading or writing More...
 

Detailed Description

Definition at line 18 of file inputHandlerLibssh.h.

Constructor & Destructor Documentation

◆ readerLibssh()

inputHandler::libssh::readerLibssh::readerLibssh ( const std::string &  aPath,
libsshCommon aHandler,
copyRequest::stateType state,
const genericStat inititalStat 
)

Definition at line 57 of file inputHandlerLibssh.cpp.

60  :
61  libsshIoCommon(aPath, aHandler),
62  reader(inititalStat) {
63  file = sftp_open(handler.sftp, path.c_str(), O_RDONLY, 0);
64  if (file == nullptr) {
65  if (sftp_get_error(handler.sftp) == SSH_FX_NO_SUCH_FILE) {
67  }
68  }
69  throwcall::sftp::badval(file, nullptr, handler, "can't open ", path, " for reading");
70  blockSize = readInitialStat.blksize;
71  }

References throwcall::sftp::badval(), ioHandle::blockSize, libsshIoCommon::file, libsshIoCommon::handler, libsshIoCommon::path, libsshCommon::sftp, and copyRequest::vanished.

Here is the call graph for this function:

◆ ~readerLibssh()

inputHandler::libssh::readerLibssh::~readerLibssh ( )
override

Definition at line 73 of file inputHandlerLibssh.cpp.

73  {
74  if (file != nullptr) {
75  if (isUnwinding()) {
76  if (sftp_close(file) == SSH_ERROR) {
78  path, "close during unwind ",
79  "sftp error ", sftp_get_error(handler.sftp),
80  ", ssh error ", ssh_get_error(handler.session));
81  }
82  return;
83  }
84  throwcall::sftp::badval(sftp_close(file), SSH_ERROR, handler,
85  "can't close ", path, " after reading");
86  }
87  }

References throwcall::sftp::badval(), errMsg::debug, and errMsg::emit().

Here is the call graph for this function:

Member Function Documentation

◆ checkUnchangedness()

void inputHandler::libssh::readerLibssh::checkUnchangedness ( )
override

Definition at line 138 of file inputHandlerLibssh.cpp.

138  {
139  auto stat = throwcall::sftp::badval(sftp_fstat(file), nullptr, handler,
140  "can't stat", path);
141  genericSftpStat readFinalStat(*stat, handler.getVfsStat(path));
142  sftp_attributes_free(stat);
143  if (readFinalStat.size != readInitialStat.size) {
144  throw delayAdvisingError("file size has changed (" +
145  std::to_string(readInitialStat.size) +
146  " -> " +
147  std::to_string(readFinalStat.size) +
148  ") during reading on " + path);
149  }
150 
151  if (!readFinalStat.isSameMtimeAs(readInitialStat)) {
152  throw delayAdvisingError("file " + path + " was modified (" +
153  std::to_string(std::chrono::duration_cast<std::chrono::duration<double>>(readFinalStat.getMtime() - readInitialStat.getMtime()).count()) +
154  "s different mtime) during reading");
155  }
156  }

References throwcall::sftp::badval(), genericStat::getMtime(), genericStat::isSameMtimeAs(), and genericStat::size.

Here is the call graph for this function:

◆ readBlock()

bool inputHandler::libssh::readerLibssh::readBlock ( block b)
override

Definition at line 97 of file inputHandlerLibssh.cpp.

97  {
98  b.clear(totalBytesRead);
99  bool lastblock = false;
100 
101  auto bytesToRead = b.max_size();
102 
103  while (b.size() + blockSize <= bytesToRead) {
105  auto bytes_read = sftp_read(file, b.bufferAt(b.size()), blockSize);
106  if (bytes_read < 0) {
107  throwcall::sftp::good0(1, handler, "read failed on ", path);
108  }
109  readRateLimit.update(bytes_read);
110  if (bytes_read == 0) {
111  lastblock = true;
112  if (totalBytesRead < readInitialStat.size) {
113  throw delayAdvisingError(path + " has shrunk while reading, (" +
114  std::to_string(readInitialStat.size) +
115  " -> " +
116  std::to_string(totalBytesRead) +
117  ")");
118  }
119  break;
120  }
121  totalBytesRead += bytes_read;
122  if (totalBytesRead > readInitialStat.size) {
123  throw delayAdvisingError(path + " has grown while reading, (" +
124  std::to_string(readInitialStat.size) +
125  " -> " +
126  std::to_string(totalBytesRead) +
127  ")");
128  }
129 
130  b.bump_size(bytes_read);
131  }
132 
133 
134  return lastblock;
135  }

References block::bufferAt(), block::bump_size(), block::clear(), throwcall::sftp::good0(), block::max_size(), readRateLimit, block::size(), throttle::watch::update(), and throttle::watch::wait().

Here is the call graph for this function:

◆ seek()

void inputHandler::libssh::readerLibssh::seek ( size_t  pos)
override

Definition at line 92 of file inputHandlerLibssh.cpp.

92  {
93  throwcall::sftp::good0(sftp_seek64(file, pos), handler,
94  "can't seek ", path, " to ", pos);
95  }

References throwcall::sftp::good0().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
delayAdvisingError
class for exceptions that advise for delays Exceptions of this kind are to be thrown when circumstanc...
Definition: inputHandler.h:22
libsshCommon::session
ssh_session session
Definition: libsshCommon.h:27
block::max_size
size_t max_size() const
Definition: block.h:22
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
libsshIoCommon::file
sftp_file file
Definition: libsshCommon.h:60
copyRequest::stateBitType::vanished
@ vanished
block::bump_size
void bump_size(size_t additionalBytes)
Definition: block.h:33
readRateLimit
throttle::watch readRateLimit
errMsg::level::debug
@ debug
ioHandle::blockSize
size_t blockSize
in bytes, block size to be used when reading or writing
Definition: ioHandle.h:17
libsshIoCommon::path
const std::string path
Definition: libsshCommon.h:59
block::bufferAt
void * bufferAt(size_t offset)
only way to access the data in the block
Definition: block.cpp:28
libsshIoCommon::handler
libsshCommon & handler
Definition: libsshCommon.h:58
libsshIoCommon::libsshIoCommon
libsshIoCommon(const std::string &aPath, libsshCommon &aHandler)
Definition: libsshCommon.cpp:198
throttle::watch::wait
void wait()
Definition: throttle.h:50
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
block::size
size_t size() const
Definition: block.h:16
libsshCommon::sftp
sftp_session sftp
Definition: libsshCommon.h:28
genericSftpStat
Definition: libsshCommon.h:16
block::clear
void clear(size_t aOffset)
Definition: block.h:28
throwcall::sftp::badval
T badval(T call, t badvalue, libsshCommon &handler, const Args &... args)
Definition: libsshCommon.h:82
throttle::watch::update
void update(double units=1.0)
Definition: throttle.h:35
libsshCommon::getVfsStat
const sftp_statvfs_struct & getVfsStat(const std::string &path)
Definition: libsshCommon.cpp:152
throwcall::sftp::good0
void good0(T call, libsshCommon &handler, const Args &... args)
Definition: libsshCommon.h:70