17 #ifndef ZNC_FILEUTILS_H
18 #define ZNC_FILEUTILS_H
20 #include <znc/zncconfig.h>
47 static bool IsReg(
const CString& sLongName,
bool bUseLstat =
false);
48 static bool IsDir(
const CString& sLongName,
bool bUseLstat =
false);
49 static bool IsChr(
const CString& sLongName,
bool bUseLstat =
false);
50 static bool IsBlk(
const CString& sLongName,
bool bUseLstat =
false);
52 static bool IsLnk(
const CString& sLongName,
bool bUseLstat =
true);
55 bool IsReg(
bool bUseLstat =
false)
const;
56 bool IsDir(
bool bUseLstat =
false)
const;
57 bool IsChr(
bool bUseLstat =
false)
const;
58 bool IsBlk(
bool bUseLstat =
false)
const;
59 bool IsFifo(
bool bUseLstat =
false)
const;
60 bool IsLnk(
bool bUseLstat =
true)
const;
61 bool IsSock(
bool bUseLstat =
false)
const;
65 bool bUseLstat =
false);
93 bool Move(
const CString& sNewFileName,
bool bOverwrite =
false);
94 bool Copy(
const CString& sNewFileName,
bool bOverwrite =
false);
98 bool bOverwrite =
false);
100 bool bOverwrite =
false);
107 mode_t iMode = 0644);
108 bool Open(
int iFlags = O_RDONLY, mode_t iMode = 0644);
109 ssize_t
Read(
char* pszBuffer,
int iBytes);
112 ssize_t
Write(
const char* pszBuffer,
size_t iBytes);
135 bool Lock(
short iType,
bool bBlocking);
148 class CDir :
public std::vector<CFile*> {
159 for (
unsigned int a = 0; a < size(); a++) {
170 DIR* dir = opendir((sDir.empty()) ?
"." : sDir.c_str());
178 while ((de = readdir(dir)) !=
nullptr) {
179 if ((strcmp(de->d_name,
".") == 0) ||
180 (strcmp(de->d_name,
"..") == 0)) {
183 if ((!sWildcard.empty()) &&
204 return cDir.
Chmod(mode);
208 unsigned int uRet = 0;
209 for (
unsigned int a = 0; a < size(); a++) {
210 if ((*
this)[a]->Chmod(mode)) {
226 unsigned int uRet = 0;
227 for (
unsigned int a = 0; a < size(); a++) {
228 if ((*
this)[a]->Delete()) {
249 char* pszCurDir = getcwd(
nullptr, 0);
Definition: FileUtils.h:148
CFile::EFileAttr m_eSortAttr
Definition: FileUtils.h:260
static bool MakeDir(const CString &sPath, mode_t iMode=0700)
size_t Fill(const CString &sDir)
Definition: FileUtils.h:166
unsigned int Delete()
Definition: FileUtils.h:225
CDir(const CString &sDir)
Definition: FileUtils.h:150
~CDir()
Definition: FileUtils.h:156
static unsigned int Chmod(mode_t mode, const CString &sWildcard, const CString &sDir=".")
Definition: FileUtils.h:200
static unsigned int Delete(const CString &sWildcard, const CString &sDir=".")
Definition: FileUtils.h:218
static CString GetCWD()
Definition: FileUtils.h:247
bool m_bDesc
Definition: FileUtils.h:261
void CleanUp()
Definition: FileUtils.h:158
unsigned int Chmod(mode_t mode)
Definition: FileUtils.h:207
static CString CheckPathPrefix(const CString &sPath, const CString &sAdd, const CString &sHomeDir="")
CDir()
Definition: FileUtils.h:154
CFile::EFileAttr GetSortAttr() const
Definition: FileUtils.h:236
static CString ChangeDir(const CString &sPath, const CString &sAdd, const CString &sHomeDir="")
bool IsDescending() const
Definition: FileUtils.h:237
size_t FillByWildcard(const CString &sDir, const CString &sWildcard)
Definition: FileUtils.h:168
Definition: FileUtils.h:30
static bool IsLnk(const CString &sLongName, bool bUseLstat=true)
static bool Copy(const CString &sOldFileName, const CString &sNewFileName, bool bOverwrite=false)
static bool Move(const CString &sOldFileName, const CString &sNewFileName, bool bOverwrite=false)
static time_t GetMTime(const CString &sFile)
bool IsChr(bool bUseLstat=false) const
static gid_t GetGID(const CString &sFile)
static time_t GetCTime(const CString &sFile)
static const CString & GetHomePath()
Definition: FileUtils.h:131
bool Move(const CString &sNewFileName, bool bOverwrite=false)
static int GetInfo(const CString &sFile, struct stat &st)
void SetFileName(const CString &sLongName)
EFileTypes
Definition: FileUtils.h:36
@ FT_BLOCK
Definition: FileUtils.h:40
@ FT_SOCK
Definition: FileUtils.h:43
@ FT_LINK
Definition: FileUtils.h:42
@ FT_FIFO
Definition: FileUtils.h:41
@ FT_CHARACTER
Definition: FileUtils.h:39
@ FT_REGULAR
Definition: FileUtils.h:37
@ FT_DIRECTORY
Definition: FileUtils.h:38
CFile(const CString &sLongName)
static bool Exists(const CString &sFile)
static bool Delete(const CString &sFileName)
static bool IsBlk(const CString &sLongName, bool bUseLstat=false)
static bool Chmod(const CString &sFile, mode_t mode)
CString m_sLongName
Absolute filename (m_sPath + "/" + m_sShortName)
Definition: FileUtils.h:144
bool HadError() const
Definition: FileUtils.h:127
CString GetLongName() const
bool IsFifo(bool bUseLstat=false) const
bool IsDir(bool bUseLstat=false) const
bool Open(int iFlags=O_RDONLY, mode_t iMode=0644)
bool TryExLock(const CString &sLockFile, int iFlags=O_RDWR|O_CREAT)
void ResetError()
Definition: FileUtils.h:128
bool ReadFile(CString &sData, size_t iMaxSize=512 *1024)
bool ReadLine(CString &sData, const CString &sDelimiter="\n")
ssize_t Write(const CString &sData)
static bool IsSock(const CString &sLongName, bool bUseLstat=false)
bool Open(const CString &sFileName, int iFlags=O_RDONLY, mode_t iMode=0644)
static off_t GetSize(const CString &sFile)
CString m_sShortName
Filename alone, without path.
Definition: FileUtils.h:145
bool IsBlk(bool bUseLstat=false) const
CString GetShortName() const
bool IsSock(bool bUseLstat=false) const
static bool IsChr(const CString &sLongName, bool bUseLstat=false)
static bool FType(const CString &sFileName, EFileTypes eType, bool bUseLstat=false)
static bool IsDir(const CString &sLongName, bool bUseLstat=false)
static void InitHomePath(const CString &sFallback)
bool IsReg(bool bUseLstat=false) const
bool IsLnk(bool bUseLstat=true) const
static bool IsReg(const CString &sLongName, bool bUseLstat=false)
static time_t GetATime(const CString &sFile)
static uid_t GetUID(const CString &sFile)
ssize_t Read(char *pszBuffer, int iBytes)
static bool IsFifo(const CString &sLongName, bool bUseLstat=false)
ssize_t Write(const char *pszBuffer, size_t iBytes)
bool Copy(const CString &sNewFileName, bool bOverwrite=false)
EFileAttr
Definition: FileUtils.h:67
@ FA_Name
Definition: FileUtils.h:67
@ FA_UID
Definition: FileUtils.h:67
@ FA_ATime
Definition: FileUtils.h:67
@ FA_CTime
Definition: FileUtils.h:67
@ FA_MTime
Definition: FileUtils.h:67
@ FA_Size
Definition: FileUtils.h:67
String class that is used inside ZNC.
Definition: ZNCString.h:68
CString TrimSuffix_n(const CString &sSuffix) const
Trim a given suffix.
static bool WildCmp(const CString &sWild, const CString &sString, CaseSensitivity cs=CaseSensitive)
Do a wildcard comparison between two strings.