20 #include <znc/zncconfig.h>
25 #include <sys/fcntl.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);
51 static bool IsFifo(
const CString& sLongName,
bool bUseLstat =
false);
52 static bool IsLnk(
const CString& sLongName,
bool bUseLstat =
true);
53 static bool IsSock(
const CString& sLongName,
bool bUseLstat =
false);
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;
99 bool Move(
const CString& sNewFileName,
bool bOverwrite =
false);
100 bool Copy(
const CString& sNewFileName,
bool bOverwrite =
false);
103 static bool Move(
const CString& sOldFileName,
const CString& sNewFileName,
bool bOverwrite =
false);
104 static bool Copy(
const CString& sOldFileName,
const CString& sNewFileName,
bool bOverwrite =
false);
105 bool Chmod(mode_t mode);
107 bool Seek(off_t uPos);
110 bool Open(
const CString& sFileName,
int iFlags = O_RDONLY, mode_t iMode = 0644);
111 bool Open(
int iFlags = O_RDONLY, mode_t iMode = 0644);
112 ssize_t
Read(
char *pszBuffer,
int iBytes);
115 ssize_t
Write(
const char *pszBuffer,
size_t iBytes);
138 bool Lock(
short iType,
bool bBlocking);
151 class CDir :
public std::vector<CFile*> {
170 for (
unsigned int a = 0; a < size(); a++) {
183 DIR* dir = opendir((sDir.empty()) ?
"." : sDir.c_str());
191 while ((de = readdir(dir)) != 0) {
192 if ((strcmp(de->d_name,
".") == 0) || (strcmp(de->d_name,
"..") == 0)) {
195 if ((!sWildcard.empty()) && (!
CString(de->d_name).
WildCmp(sWildcard))) {
210 return cDir.
Chmod(mode);
214 unsigned int uRet = 0;
215 for (
unsigned int a = 0; a < size(); a++) {
216 if ((*
this)[a]->Chmod(mode)) {
231 unsigned int uRet = 0;
232 for (
unsigned int a = 0; a < size(); a++) {
233 if ((*
this)[a]->Delete()) {
252 char * pszCurDir = getcwd(NULL, 0);
266 #endif // !_FILEUTILS_H
static bool IsChr(const CString &sLongName, bool bUseLstat=false)
static CString CheckPathPrefix(const CString &sPath, const CString &sAdd, const CString &sHomeDir="")
static CString ChangeDir(const CString &sPath, const CString &sAdd, const CString &sHomeDir="")
Definition: FileUtils.h:67
bool m_bDesc
Definition: FileUtils.h:264
static bool MakeDir(const CString &sPath, mode_t iMode=0700)
CString TrimSuffix_n(const CString &sSuffix) const
Trim a given suffix.
static bool IsFifo(const CString &sLongName, bool bUseLstat=false)
static bool IsLnk(const CString &sLongName, bool bUseLstat=true)
Definition: FileUtils.h:41
static unsigned int Delete(const CString &sWildcard, const CString &sDir=".")
Definition: FileUtils.h:224
Definition: FileUtils.h:69
Definition: FileUtils.h:68
EFileAttr
Definition: FileUtils.h:66
static bool IsBlk(const CString &sLongName, bool bUseLstat=false)
static unsigned int Chmod(mode_t mode, const CString &sWildcard, const CString &sDir=".")
Definition: FileUtils.h:207
CString m_sShortName
Filename alone, without path.
Definition: FileUtils.h:148
CString m_sLongName
Absolute filename (m_sPath + "/" + m_sShortName)
Definition: FileUtils.h:147
static void InitHomePath(const CString &sFallback)
Definition: FileUtils.h:37
static bool FType(const CString &sFileName, EFileTypes eType, bool bUseLstat=false)
bool HadError() const
Definition: FileUtils.h:130
CDir()
Definition: FileUtils.h:160
bool ReadLine(CString &sData, const CString &sDelimiter="\n")
static bool IsReg(const CString &sLongName, bool bUseLstat=false)
Definition: FileUtils.h:30
Definition: FileUtils.h:39
Definition: FileUtils.h:151
Definition: FileUtils.h:38
String class that is used inside ZNC.
Definition: ZNCString.h:67
unsigned int Delete()
Definition: FileUtils.h:230
static CString GetCWD()
Definition: FileUtils.h:250
static const CString & GetHomePath()
Definition: FileUtils.h:134
void ResetError()
Definition: FileUtils.h:131
size_t FillByWildcard(const CString &sDir, const CString &sWildcard)
Definition: FileUtils.h:181
static int GetInfo(const CString &sFile, struct stat &st)
Definition: FileUtils.h:71
~CDir()
Definition: FileUtils.h:165
CFile::EFileAttr GetSortAttr()
Definition: FileUtils.h:241
static bool WildCmp(const CString &sWild, const CString &sString)
Do a wildcard comparision between two strings.
static bool IsSock(const CString &sLongName, bool bUseLstat=false)
Definition: FileUtils.h:70
size_t Fill(const CString &sDir)
Definition: FileUtils.h:177
bool Open(const CString &sFileName, int iFlags=O_RDONLY, mode_t iMode=0644)
static bool IsDir(const CString &sLongName, bool bUseLstat=false)
CString GetLongName() const
Definition: FileUtils.h:40
bool ReadFile(CString &sData, size_t iMaxSize=512 *1024)
EFileTypes
Definition: FileUtils.h:36
void CleanUp()
Definition: FileUtils.h:169
CString GetShortName() const
bool Move(const CString &sNewFileName, bool bOverwrite=false)
CFile::EFileAttr m_eSortAttr
Definition: FileUtils.h:263
ssize_t Write(const char *pszBuffer, size_t iBytes)
Definition: FileUtils.h:43
CDir(const CString &sDir)
Definition: FileUtils.h:154
bool IsDescending()
Definition: FileUtils.h:242
bool Copy(const CString &sNewFileName, bool bOverwrite=false)
unsigned int Chmod(mode_t mode)
Definition: FileUtils.h:213
ssize_t Read(char *pszBuffer, int iBytes)
Definition: FileUtils.h:72
Definition: FileUtils.h:42
void SetFileName(const CString &sLongName)