27#ifndef FILEUTILITIES_H
28#define FILEUTILITIES_H
37#include <boost/optional.hpp>
40#if !defined(SIZE_T_MAX)
41# define SIZE_T_MAX SIZE_MAX
48const mode_t S_IRXALL = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
49const mode_t S_IRALL = S_IRUSR | S_IRGRP | S_IROTH;
55std::vector<std::string> splitPath(
const std::string& path);
64bool mkdirRecursive(
const std::string& path, mode_t mode = S_IRWXU);
73bool mkdirRecursiveAt(
const std::string& fullPath,
int parentDirectoryFd, mode_t mode = S_IRWXU);
78bool exists(
const std::string& path);
86int copyFile(
const std::string & to,
const std::string & from);
87int copyFile(
const char *to,
const char *from);
95void deleteDirectory(
const std::string& directoryName);
103void deleteDirectoryAt(
int parentDirectoryFd,
const std::string& directoryName);
112 bool deleteFilesInDirectory(
const std::string& directoryName);
119bool deleteFile(
const std::string & filePath);
126std::vector<std::string> getFilesInDirectory(
int dirFd);
127std::vector<std::string> getFilesInDirectory(
const std::string & dirName,
bool fullPaths =
false);
134std::string resolvePath(
const std::string& in);
140std::vector<uint8_t> fileContents(
const std::string& filepath);
147std::vector<uint8_t> fileContents(
int fd,
size_t maxSize = SIZE_T_MAX);
148std::vector<uint8_t> fileContents(
int dirFd,
const std::string& filepath,
size_t maxSize = SIZE_T_MAX);
154bool compareFilesExactly(
const std::string & filePathApples,
const std::string & filePathOranges);
163bool createTextFile(
const std::string& filePath,
const std::string& contents, mode_t mode = S_IRWXU);
164bool createTextFileAt(
int dirFd,
const std::string& filePath,
const std::string& contents, mode_t mode = S_IRWXU);
169std::string readTextStream(FILE *fp);
190boost::optional<std::string> getXAttrib(
int fileFd,
const std::string& key);
197boost::optional<std::string> getXAttrib(
const std::string& filePath,
const std::string& key);
223bool setXAttrib(
int fd,
const std::string& key,
const std::string& value,
int flags = 0);
224bool setXAttrib(
const std::string& filePath,
const std::string& key,
const std::string& value,
int flags = 0);
231std::string fileMD5(
const std::string & filePath);
232std::string fileMD5(
int fd);
242int getDeviceFreeMegabytes(
const std::string & path);
249size_t getDirectorySizeInKb(
const std::string &path );