|
|
|
|
|
|
|
|
// Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
// Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
//==============================================================================
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
#include <cerrno>
|
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
#include "filesystem.hpp"
|
|
|
#include "filesystem.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileReference::FileReference(std::string fileName) :
|
|
|
FileReference::FileReference(std::string fileName) :
|
|
|
name(fileName),
|
|
|
name(fileName),
|
|
|
timestamp(0),
|
|
|
|
|
|
|
|
|
modTimestamp(0),
|
|
|
size_bytes(0),
|
|
|
size_bytes(0),
|
|
|
fileExists(false),
|
|
|
fileExists(false),
|
|
|
fileIsDirectory(false) {
|
|
|
fileIsDirectory(false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *realPath = realpath(name.c_str(), NULL);
|
|
|
char *realPath = realpath(name.c_str(), NULL);
|
|
|
|
|
|
|
|
|
if (NULL == path) {
|
|
|
|
|
|
|
|
|
if (NULL == realPath) {
|
|
|
|
|
|
|
|
|
// Nothing to do if the file doesn't exist.
|
|
|
// Nothing to do if the file doesn't exist.
|
|
|
if (ENOENT == errno) {
|
|
|
if (ENOENT == errno) {
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Something went wrong.
|
|
|
// Something went wrong.
|
|
|
throw std::runtime_error("Error checking file \"" + name "\": " +
|
|
|
|
|
|
|
|
|
throw std::runtime_error("Error checking file \"" + name + "\": " +
|
|
|
getErrorText());
|
|
|
getErrorText());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
path = *realPath;
|
|
|
|
|
|
|
|
|
path.assign(realPath);
|
|
|
free(realPath);
|
|
|
free(realPath);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Something went wrong.
|
|
|
// Something went wrong.
|
|
|
throw std::runtime_error("Error updating status of file \"" +
|
|
|
throw std::runtime_error("Error updating status of file \"" +
|
|
|
path "\": " + getErrorText());
|
|
|
|
|
|
|
|
|
path + "\": " + getErrorText());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return modTimestamp;
|
|
|
return modTimestamp;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
long FileReference::Size() const {
|
|
|
|
|
|
|
|
|
size_t FileReference::Size() const {
|
|
|
return size_bytes;
|
|
|
return size_bytes;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
return path;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
time_t FileReference::exists() const {
|
|
|
|
|
|
|
|
|
bool FileReference::exists() const {
|
|
|
return fileExists;
|
|
|
return fileExists;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
time_t FileReference::isDirectory() const {
|
|
|
|
|
|
|
|
|
bool FileReference::isDirectory() const {
|
|
|
return fileIsDirectory;
|
|
|
return fileIsDirectory;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|