ewmscp  ..
Public Member Functions | List of all members
vimWrite Class Reference
Inheritance diagram for vimWrite:
[legend]
Collaboration diagram for vimWrite:
[legend]

Public Member Functions

 vimWrite ()
 
void execute (const std::vector< std::string > &remainingOptions) override
 
- Public Member Functions inherited from baseTest
 baseTest (const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
 
void ensuredWrite (int fd, const std::string &data)
 
void ensuredRead (int fd, std::string &data)
 
void Execute (const std::vector< std::string > &remainingOptions)
 

Additional Inherited Members

- Static Public Member Functions inherited from baseTest
static std::map< std::string, baseTest * > & getList ()
 
static void setUpOptions ()
 
static const std::string & getDescriptions ()
 
- Protected Attributes inherited from baseTest
std::string name
 
std::string description
 
std::list< std::pair< std::string, std::string > > parameters
 
std::list< std::pair< options::base &, std::string > > options
 
std::set< std::string > createdFiles
 
- Static Protected Attributes inherited from baseTest
static options::single< unsigned int > repeat
 
static options::single< bool > cleanup
 
static options::single< bool > urandom
 
static options::single< bool > einsZweiDrei
 
static options::single< std::string > contentFile
 
static options::single< size_t > size
 
static options::single< unsigned int > blocks
 
static options::single< std::string > content
 
static options::single< bool > truncate
 
static options::single< std::chrono::duration< double > > time
 
static options::single< unsigned long > syncus
 
static options::single< unsigned long > skewus
 
static std::string descriptions = "\npossible actions and their parameters:\n"
 

Detailed Description

Definition at line 298 of file fileOpsTests.cpp.

Constructor & Destructor Documentation

◆ vimWrite()

vimWrite::vimWrite ( )
inline

Definition at line 300 of file fileOpsTests.cpp.

300  : baseTest("vimWrite",
301  "simulate the way vim writes a file", {
302  {"file", "path to the file to create"
303  }
304  }) {};

Member Function Documentation

◆ execute()

void vimWrite::execute ( const std::vector< std::string > &  remainingOptions)
inlineoverridevirtual

Implements baseTest.

Definition at line 306 of file fileOpsTests.cpp.

306  {
307  auto file = remainingOptions.at(0);
308  std::string tildeFile(file);
309  tildeFile += "~";
310  struct stat buf;
311  unlink(tildeFile.c_str());
312  if (stat(file.c_str(), &buf) != 0) {
313  if (errno == ENOENT) {
314  auto fd = throwcall::badval(open(file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644), -1,
315  "open ", file);
316  ensuredWrite(fd, "this is the old file...\n");
317  ensuredWrite(fd, content);
318  ensuredWrite(fd, "this is the old file...\n");
319  throwcall::good0(close(fd), "close ", file);
320  }
321  }
322  throwcall::good0(rename(file.c_str(), tildeFile.c_str()),
323  "rename ", file, " to ", tildeFile);
324  auto fd = throwcall::badval(open(file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644), -1,
325  "open ", file);
326  ensuredWrite(fd, content);
327  throwcall::good0(fsync(fd), "sync ", file);
328  throwcall::good0(close(fd), "close ", file);
329  throwcall::good0(unlink(tildeFile.c_str()), "unlink ", tildeFile);
330  createdFiles.emplace(file);
331  }

References throwcall::badval(), baseTest::content, baseTest::createdFiles, baseTest::ensuredWrite(), and throwcall::good0().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
baseTest::content
static options::single< std::string > content
Definition: fileOpsTests.cpp:51
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
baseTest::createdFiles
std::set< std::string > createdFiles
Definition: fileOpsTests.cpp:42
baseTest::baseTest
baseTest(const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
Definition: fileOpsTests.cpp:68
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
baseTest::ensuredWrite
void ensuredWrite(int fd, const std::string &data)
Definition: fileOpsTests.cpp:106