ewmscp  ..
Public Types | Public Member Functions | Public Attributes | Static Private Member Functions | List of all members
genericStat Class Reference

generic stat abstraction class Used to abstract the variants of the stat structure. More...

#include <genericStat.h>

Inheritance diagram for genericStat:
[legend]

Public Types

typedef std::chrono::system_clock clock_type
 

Public Member Functions

 genericStat (const struct stat &statBuf, const clock_type::duration &aTimeResolution)
 
 genericStat (const struct stat64 &statBuf, const clock_type::duration &aTimeResolution)
 
 genericStat ()
 
void getAtime (struct timespec &spec) const
 
void getMtime (struct timespec &spec) const
 
void getAtime (struct timeval &spec) const
 
void getMtime (struct timeval &spec) const
 
void getAtime (std::string &spec) const
 
void getMtime (std::string &spec) const
 
clock_type::time_point getMtime () const
 
bool isNewerThan (const genericStat &that) const
 
bool isSameMtimeAs (const genericStat &that) const
 
bool isDir () const
 
bool isLink () const
 
bool isRegularFile () const
 

Public Attributes

dev_t device
 
size_t size
 
size_t sizeOnDisk
 
size_t blksize
 
clock_type::time_point aTime
 
clock_type::time_point mTime
 
clock_type::duration timeResolution
 
mode_t mode
 
uid_t ownerUid
 
gid_t ownerGid
 

Static Private Member Functions

static void chronoToTimespec (struct timespec &spec, const clock_type::time_point &Chrono)
 
static void chronoToTimeval (struct timeval &spec, const clock_type::time_point &Chrono)
 
static void chronoToString (std::string &str, const clock_type::time_point &Chrono)
 

Detailed Description

generic stat abstraction class Used to abstract the variants of the stat structure.

Provides comparison functions, that in the case of the time comparisons consider the time resolution of the underlying stat.

Definition at line 12 of file genericStat.h.

Member Typedef Documentation

◆ clock_type

typedef std::chrono::system_clock genericStat::clock_type

Definition at line 14 of file genericStat.h.

Constructor & Destructor Documentation

◆ genericStat() [1/3]

genericStat::genericStat ( const struct stat &  statBuf,
const clock_type::duration &  aTimeResolution 
)

Definition at line 10 of file genericStat.cpp.

10  :
11  device(statBuf.st_dev),
12  size(statBuf.st_size),
13  sizeOnDisk(statBuf.st_blocks * 512),
14  blksize(statBuf.st_blksize),
15  aTime(std::chrono::seconds(statBuf.st_atim.tv_sec)
16  + std::chrono::nanoseconds(statBuf.st_atim.tv_nsec)),
17  mTime(std::chrono::seconds(statBuf.st_mtim.tv_sec)
18  + std::chrono::nanoseconds(statBuf.st_mtim.tv_nsec)),
19  timeResolution(aTimeResolution),
20  mode(statBuf.st_mode),
21  ownerUid(statBuf.st_uid),
22  ownerGid(statBuf.st_gid) {
23 }

◆ genericStat() [2/3]

genericStat::genericStat ( const struct stat64 &  statBuf,
const clock_type::duration &  aTimeResolution 
)

Definition at line 24 of file genericStat.cpp.

24  :
25  device(statBuf.st_dev),
26  size(statBuf.st_size),
27  sizeOnDisk(statBuf.st_blocks * 512),
28  blksize(statBuf.st_blksize),
29  aTime(std::chrono::seconds(statBuf.st_atim.tv_sec)
30  + std::chrono::nanoseconds(statBuf.st_atim.tv_nsec)),
31  mTime(std::chrono::seconds(statBuf.st_mtim.tv_sec)
32  + std::chrono::nanoseconds(statBuf.st_mtim.tv_nsec)),
33  timeResolution(aTimeResolution),
34  mode(statBuf.st_mode),
35  ownerUid(statBuf.st_uid),
36  ownerGid(statBuf.st_gid) {
37 }

◆ genericStat() [3/3]

genericStat::genericStat ( )
default

Member Function Documentation

◆ chronoToString()

void genericStat::chronoToString ( std::string &  str,
const clock_type::time_point &  Chrono 
)
staticprivate

Definition at line 47 of file genericStat.cpp.

47  {
48  struct tm time;
49  time_t t = std::chrono::duration_cast<std::chrono::seconds>(Chrono.time_since_epoch()).count();
50  gmtime_r(&t, &time);
51  char buffer[123];
52  strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S.", &time);
53  spec = buffer;
54  std::ostringstream buf2;
55  buf2 << std::setw(6) << std::setfill('0')
56  << std::chrono::duration_cast<std::chrono::microseconds>(Chrono.time_since_epoch()).count() % 1000000;
57  // std::sprintf(buffer, "%06ld", std::chrono::duration_cast<std::chrono::microseconds>(Chrono.time_since_epoch()).count() % 1000000);
58  spec += buf2.str();
59 }

Referenced by getAtime(), and getMtime().

Here is the caller graph for this function:

◆ chronoToTimespec()

void genericStat::chronoToTimespec ( struct timespec &  spec,
const clock_type::time_point &  Chrono 
)
staticprivate

Definition at line 39 of file genericStat.cpp.

39  {
40  spec.tv_sec = std::chrono::duration_cast<std::chrono::seconds>(Chrono.time_since_epoch()).count();
41  spec.tv_nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(Chrono.time_since_epoch()).count() % 1000000000;
42 }

Referenced by getAtime(), and getMtime().

Here is the caller graph for this function:

◆ chronoToTimeval()

void genericStat::chronoToTimeval ( struct timeval &  spec,
const clock_type::time_point &  Chrono 
)
staticprivate

Definition at line 43 of file genericStat.cpp.

43  {
44  spec.tv_sec = std::chrono::duration_cast<std::chrono::seconds>(Chrono.time_since_epoch()).count();
45  spec.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(Chrono.time_since_epoch()).count() % 1000000;
46 }

Referenced by getAtime(), and getMtime().

Here is the caller graph for this function:

◆ getAtime() [1/3]

void genericStat::getAtime ( std::string &  spec) const

Definition at line 74 of file genericStat.cpp.

74  {
75  chronoToString(spec, aTime);
76 }

References aTime, and chronoToString().

Here is the call graph for this function:

◆ getAtime() [2/3]

void genericStat::getAtime ( struct timespec &  spec) const

Definition at line 62 of file genericStat.cpp.

62  {
63  chronoToTimespec(spec, aTime);
64 }

References aTime, and chronoToTimespec().

Referenced by outputHandler::libssh::writerLibssh::doAttributePreservations(), outputHandler::posixFile::writerPosixFile::doAttributePreservations(), and outputHandler::daosFs::writerDaosFs::doAttributePreservations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAtime() [3/3]

void genericStat::getAtime ( struct timeval &  spec) const

Definition at line 68 of file genericStat.cpp.

68  {
69  chronoToTimeval(spec, aTime);
70 }

References aTime, and chronoToTimeval().

Here is the call graph for this function:

◆ getMtime() [1/4]

genericStat::clock_type::time_point genericStat::getMtime ( ) const

Definition at line 80 of file genericStat.cpp.

80  {
81  return mTime;
82 }

References mTime.

◆ getMtime() [2/4]

void genericStat::getMtime ( std::string &  spec) const

Definition at line 77 of file genericStat.cpp.

77  {
78  chronoToString(spec, mTime);
79 }

References chronoToString(), and mTime.

Here is the call graph for this function:

◆ getMtime() [3/4]

void genericStat::getMtime ( struct timespec &  spec) const

◆ getMtime() [4/4]

void genericStat::getMtime ( struct timeval &  spec) const

Definition at line 71 of file genericStat.cpp.

71  {
72  chronoToTimeval(spec, mTime);
73 }

References chronoToTimeval(), and mTime.

Here is the call graph for this function:

◆ isDir()

bool genericStat::isDir ( ) const

Definition at line 92 of file genericStat.cpp.

92  {
93  return S_ISDIR(mode);
94 };

References mode.

Referenced by outputHandler::dcap::rename(), outputHandler::Gpfs::rename(), outputHandler::libssh::rename(), outputHandler::posixFile::rename(), and outputHandler::daosFs::rename().

Here is the caller graph for this function:

◆ isLink()

bool genericStat::isLink ( ) const

Definition at line 95 of file genericStat.cpp.

95  {
96  return S_ISLNK(mode);
97 };

References mode.

◆ isNewerThan()

bool genericStat::isNewerThan ( const genericStat that) const

Definition at line 84 of file genericStat.cpp.

84  {
85  return that.mTime - mTime < std::max(timeResolution, that.timeResolution);
86 }

References mTime, and timeResolution.

◆ isRegularFile()

bool genericStat::isRegularFile ( ) const

Definition at line 98 of file genericStat.cpp.

98  {
99  return S_ISREG(mode);
100 };

References mode.

◆ isSameMtimeAs()

bool genericStat::isSameMtimeAs ( const genericStat that) const

Definition at line 87 of file genericStat.cpp.

87  {
88  return (that.mTime - mTime < std::max(timeResolution, that.timeResolution)) &&
89  (mTime - that.mTime < std::max(timeResolution, that.timeResolution));
90 }

References mTime, and timeResolution.

Referenced by inputHandler::dcap::readerDcap::checkUnchangedness(), inputHandler::daosFs::readerDaosFs::checkUnchangedness(), inputHandler::libssh::readerLibssh::checkUnchangedness(), inputHandler::posixFile::readerPosixFile::checkUnchangedness(), outputHandler::dcap::rename(), outputHandler::libssh::rename(), outputHandler::posixFile::rename(), and outputHandler::daosFs::rename().

Here is the caller graph for this function:

Member Data Documentation

◆ aTime

clock_type::time_point genericStat::aTime

Definition at line 19 of file genericStat.h.

Referenced by genericSftpStat::genericSftpStat(), and getAtime().

◆ blksize

size_t genericStat::blksize

◆ device

dev_t genericStat::device

◆ mode

mode_t genericStat::mode

◆ mTime

clock_type::time_point genericStat::mTime

◆ ownerGid

gid_t genericStat::ownerGid

◆ ownerUid

uid_t genericStat::ownerUid

◆ size

size_t genericStat::size

◆ sizeOnDisk

size_t genericStat::sizeOnDisk

Definition at line 17 of file genericStat.h.

Referenced by genericSftpStat::genericSftpStat(), and operator<<().

◆ timeResolution

clock_type::duration genericStat::timeResolution

Definition at line 21 of file genericStat.h.

Referenced by genericSftpStat::genericSftpStat(), isNewerThan(), and isSameMtimeAs().


The documentation for this class was generated from the following files:
genericStat::ownerGid
gid_t ownerGid
Definition: genericStat.h:24
genericStat::mode
mode_t mode
Definition: genericStat.h:22
genericStat::mTime
clock_type::time_point mTime
Definition: genericStat.h:20
genericStat::sizeOnDisk
size_t sizeOnDisk
Definition: genericStat.h:17
genericStat::aTime
clock_type::time_point aTime
Definition: genericStat.h:19
genericStat::blksize
size_t blksize
Definition: genericStat.h:18
genericStat::size
size_t size
Definition: genericStat.h:16
genericStat::chronoToTimeval
static void chronoToTimeval(struct timeval &spec, const clock_type::time_point &Chrono)
Definition: genericStat.cpp:43
genericStat::device
dev_t device
Definition: genericStat.h:15
genericStat::timeResolution
clock_type::duration timeResolution
Definition: genericStat.h:21
genericStat::ownerUid
uid_t ownerUid
Definition: genericStat.h:23
genericStat::chronoToString
static void chronoToString(std::string &str, const clock_type::time_point &Chrono)
Definition: genericStat.cpp:47
genericStat::chronoToTimespec
static void chronoToTimespec(struct timespec &spec, const clock_type::time_point &Chrono)
Definition: genericStat.cpp:39