ewmscp  ..
Functions
Collaboration diagram for follow mode for inotify_watch:

Functions

void followInotifyWatchRequestProvider::followStream (std::istream &stream) override
 

Detailed Description

The InotifyWatch request provider takes the output of The inotify_watch command. to create copy requests.

The format of the inofify watch output is:

<cmd> <timestamp> <filename>

<cmd> is the two-character command, valid are cp to copy a file, rm to remove a file and mv to move (rename) a file. <timestamp> is a decimal double value as seconds since the epoch of the time that the event leading to the request happened, i.e. was seen by inotify_watch. <filename> is the filename of the file to be copied/renamed/deleted, relative to the working directory. In the case of the mv command an additional line with the move target follows.

The end-of-line mark is by default the newline character, but if the -0 option is given it's the NUL character.

ig is a special tag for keepalive messages, which are ignored. They are needed to keep a ssh session from the inotify_watch node to the ewmscp node open.

Because some files tend to be changed quickly after a first close-after-write they should be processed in a delayed queue.

Function Documentation

◆ followStream()

void followInotifyWatchRequestProvider::followStream ( std::istream &  stream)
overrideprivatevirtual

Implements followRequestProvider.

Definition at line 38 of file followInotifyWatchRequestProvider.cpp.

38  {
39  char delimiter = nullDelimiter ? '\0' : '\n';
40  std::string line;
41 
42  while (stream) {
43  if (stopRequest::Requested()) {
45  "request provider", "stop request received"
46  , "ignoring further requests");
47  break;
48  }
49  char cmdbuff[4] = {0, 0, 0, 0};
50  stream.read(cmdbuff, 3);
51  auto readTime = copyRequest::clock_type::now();
52  if (stream.eof()) {
53  break;
54  }
55 
56  double timestampAsDouble;
57  stream >> timestampAsDouble;
58  auto timestamp = copyRequest::clock_type::time_point(std::chrono::duration_cast<copyRequest::clock_type::duration>(std::chrono::duration<double>(timestampAsDouble)));
59  stream.ignore(); // skip one character after timestamp
60  std::getline(stream, line, delimiter);
61 
62  if (strcmp(cmdbuff, "ig ") == 0) { // ignore this line, to be used as keepalive
63  continue;
64  }
65 
66  if (strcmp(cmdbuff, "mv ") == 0) { // special case move...
67  std::string target;
68  std::getline(stream, target, delimiter);
69  std::string fromPath;
70  auto mapEntryD = getDstPath(line, fromPath);
71  std::string dstPath;
72  auto mapEntryS = getDstPath(target, dstPath);
73  handleMove(target, dstPath, fromPath, line, mapEntryD, timestamp);
74  } else {
75  auto requestForRemoval = strcmp(cmdbuff, "rm ") == 0;
76  std::string dstPath;
77  auto mapEntry = getDstPath(line, dstPath);
78 
79  handleOther(line, dstPath, mapEntry, timestamp, requestForRemoval);
80  }
81  auto enqueueDoneTime = copyRequest::clock_type::now();
82  copyRequest::base::tEnqueueStat.addValue(enqueueDoneTime - readTime);
83 
84  }
85 }

References statCollector::typed< T >::addValue(), errMsg::emit(), requestProvider::getDstPath(), followRequestProvider::handleMove(), followRequestProvider::handleOther(), errMsg::info, followRequestProvider::nullDelimiter, stopRequest::Requested(), and copyRequest::base::tEnqueueStat.

Here is the call graph for this function:
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
copyRequest::base::tEnqueueStat
static statCollector::typed< copyRequest::clock_type::duration > tEnqueueStat
Definition: copyRequest.h:320
followRequestProvider::handleMove
virtual void handleMove(const std::string &srcPath, const std::string &dstPath, const std::string &fromPath, const std::string &origPath, const singleMap &mapEntry, copyRequest::clock_type::time_point timestamp)
Definition: followRequestProvider.cpp:31
errMsg::level::info
@ info
followRequestProvider::nullDelimiter
static options::single< bool > nullDelimiter
Definition: followRequestProvider.h:20
stopRequest::Requested
static bool Requested()
Definition: ewmscp.cpp:153
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
statCollector::typed::addValue
void addValue(T value)
Definition: statCollector.h:37
requestProvider::getDstPath
virtual const singleMap & getDstPath(const std::string &source, std::string &destination, bool baseNameOnly=false)
get detstination papth for a given source path
Definition: requestProvider.cpp:30
followRequestProvider::handleOther
virtual void handleOther(const std::string &srcPath, const std::string &dstPath, const singleMap &mapEntry, copyRequest::clock_type::time_point timestamp, bool requestForRemoval)
Definition: followRequestProvider.cpp:41