LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE), // 11801
LOC_DELETE_TREE_2, // 11802
LOC_DELETE_TREE_3, // 11803
+ LOC_SET_TIMES_1, // 11804
};
+QDateTime ReFileUtils::m_undefinedTime;
+
/**
* Constructor.
*/
ReTreeStatistic::ReTreeStatistic() :
- m_files(0),
- m_directories(0),
- m_fileSizes(0L) {
-}
-
-/**
- * Returns whether a path is an absolute path.
- *
- * @param path the path to test
- * @return <code>true</code>: the path is absolute<br>
- * <code>false</code>: the path is relative
- */
-bool ReFileUtils::isAbsolutPath(const QString& path) {
- bool rc;
-#ifdef __linux__
- rc = path.startsWith(OS_SEPARATOR);
-#else
- rc = path.length() > 3 && path.at(1) == ':' && path.at(2) == OS_SEPARATOR
- || path.startsWith("\\\\");
-#endif
- return rc;
-}
-
-/**
- * Returns whether a path is an absolute path.
- *
- * @param path the path to test
- * @return <code>true</code>: the path is absolute<br>
- * <code>false</code>: the path is relative
- */
-bool ReFileUtils::isAbsolutPath(const char* path)
-{
- bool rc;
-#ifdef __linux__
- rc = path[0] == OS_SEPARATOR;
-#else
- rc = isalpha(path[0]) && path[1] == ':' && path[2] == OS_SEPARATOR
- || path[0] == OS_SEPARATOR && path[1] == OS_SEPARATOR;
-#endif
- return rc;
-}
-
-/** Sets the read position of a file.
- * @param file file to process
- * @param offset the position. @see <code>whence</code>
- * @param whence SEEK_SET: offset is absolute (from file's start)
- * SEEK_END: offset is relative to the file' end
- * SEEK_CUR: offset is relative to the current position
- * @return 0: success<br>
- * otherwise: error code
- */
-int ReFileUtils::seek(FILE* file, int64_t offset, int whence){
- int rc;
-#if defined __linux__
- rc = fseeko(file, offset, whence);
-#elif defined __WIN32__
- rc = _fseek64(file, offset, whence);
-#endif
- return rc;
-}
-
-/**
- * Returns the current file position.
- *
- * @param file file to process
- * @return < 0: error occurred<br>
- * otherwise: the current read/write position (from the file's start)
- */
-int64_t ReFileUtils::tell(FILE* file)
-{
- int64_t rc;
-#if defined __linux__
- rc = ftello(file);
-#elif defined __WIN32__
- rc = _ftell64(file);
-#endif
- return rc;
+ m_files(0),
+ m_directories(0),
+ m_fileSizes(0L) {
}
/**
* @return <code>true</code>: all files deleted<br>
* <code>false</code>: at least one deletion failed
*/
+
bool ReFileUtils::deleteTree(const QString& path, bool withBase,
- ReLogger* logger) {
+ ReLogger* logger) {
bool rc = true;
QDir dir(path);
if (dir.exists(path)) {
QFileInfo info;
QStringList names = dir.entryList(
- QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs
- | QDir::Files);
+ QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs
+ | QDir::Files);
QStringList::const_iterator it;
for (it = names.constBegin(); it != names.constEnd(); ++it) {
QString full(path);
rc = false;
if (logger != NULL)
logger->logv(LOG_ERROR, LOC_DELETE_TREE_1,
- "cannot delete directory (%d): %s", errno,
- full.toUtf8().constData());
+ "cannot delete directory (%d): %s", errno,
+ full.toUtf8().constData());
}
} else {
if (!QFile::remove(full)) {
rc = false;
if (logger != NULL)
logger->logv(LOG_ERROR, LOC_DELETE_TREE_2,
- "cannot delete file (%d): %s", errno,
- full.toUtf8().constData());
+ "cannot delete file (%d): %s", errno,
+ full.toUtf8().constData());
}
}
}
if (withBase && (rmdir(path.toUtf8())) != 0) {
rc = false;
logger->logv(LOG_ERROR, LOC_DELETE_TREE_3,
- "cannot delete directory (%d): %s", errno, path.toUtf8());
+ "cannot delete directory (%d): %s", errno, path.toUtf8());
}
return rc;
}
+/**
+ * Returns whether a path is an absolute path.
+ *
+ * @param path the path to test
+ * @return <code>true</code>: the path is absolute<br>
+ * <code>false</code>: the path is relative
+ */
+bool ReFileUtils::isAbsolutPath(const QString& path) {
+ bool rc;
+#ifdef __linux__
+ rc = path.startsWith(OS_SEPARATOR);
+#else
+ rc = path.length() > 3 && path.at(1) == ':' && path.at(2) == OS_SEPARATOR
+ || path.startsWith("\\\\");
+#endif
+ return rc;
+}
+
+/**
+ * Returns whether a path is an absolute path.
+ *
+ * @param path the path to test
+ * @return <code>true</code>: the path is absolute<br>
+ * <code>false</code>: the path is relative
+ */
+bool ReFileUtils::isAbsolutPath(const char* path) {
+ bool rc;
+#ifdef __linux__
+ rc = path[0] == OS_SEPARATOR;
+#else
+ rc = isalpha(path[0]) && path[1] == ':' && path[2] == OS_SEPARATOR
+ || path[0] == OS_SEPARATOR && path[1] == OS_SEPARATOR;
+#endif
+ return rc;
+}
/**
* Reads a string from a given file.
* @return <code>buffer</code> (for chaining)
*/
QByteArray& ReFileUtils::readFromFile(const char* filename,
- QByteArray& buffer) {
+ QByteArray& buffer) {
FILE* fp = fopen(filename, "r");
if (fp != NULL) {
struct stat info;
return buffer;
}
+/**
+ * Sets the filetimes.
+ *
+ * @param filename name of the file to change
+ * @param modified the new modification time
+ * @param accessed the new access time.
+ * If <code>m_undefinedTime</code> the current time is taken
+ * @return <code>true</code>: success
+ */
+bool ReFileUtils::setTimes(const char* filename, const QDateTime& modified,
+ const QDateTime& accessed, ReLogger* logger) {
+ bool rc = true;
+#if defined __linux__
+ struct timeval vals[2];
+ int64_t millisec = accessed == m_undefinedTime
+ ? QDateTime::currentMSecsSinceEpoch() : accessed.toMSecsSinceEpoch();
+ vals[0].tv_sec = millisec / 1000;
+ vals[0].tv_usec = millisec % 1000 * 1000;
+ millisec = modified.toMSecsSinceEpoch();
+ vals[1].tv_sec = millisec / 1000;
+ vals[1].tv_usec = millisec % 1000 * 1000;
+ if (utimes(filename, vals) != 0) {
+ if (logger != NULL)
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
+ "cannot change times (%d): $s", errno, filename);
+ rc = false;
+ }
+#elif defined __WIN32__
+#error "not implemented"
+#endif
+ return rc;
+}
+
+/** Sets the read position of a file.
+ * @param file file to process
+ * @param offset the position. @see <code>whence</code>
+ * @param whence SEEK_SET: offset is absolute (from file's start)
+ * SEEK_END: offset is relative to the file' end
+ * SEEK_CUR: offset is relative to the current position
+ * @return 0: success<br>
+ * otherwise: error code
+ */
+int ReFileUtils::seek(FILE* file, int64_t offset, int whence) {
+ int rc;
+#if defined __linux__
+ rc = fseeko(file, offset, whence);
+#elif defined __WIN32__
+ rc = _fseek64(file, offset, whence);
+#endif
+ return rc;
+}
+
+/**
+ * Returns the current file position.
+ *
+ * @param file file to process
+ * @return < 0: error occurred<br>
+ * otherwise: the current read/write position (from the file's start)
+ */
+int64_t ReFileUtils::tell(FILE* file) {
+ int64_t rc;
+#if defined __linux__
+ rc = ftello(file);
+#elif defined __WIN32__
+ rc = _ftell64(file);
+#endif
+ return rc;
+}
+
/**
* @brief Returns the name of a directory in the temp dir.
*
* @return the name of an existing directory
*/
QByteArray ReFileUtils::tempDir(const char* node, const char* parent,
- bool withSeparator) {
+ bool withSeparator) {
#if defined __linux__
QByteArray temp("/tmp");
static const char* firstVar = "TMP";
* @return the full name of a temporary file
*/
QByteArray ReFileUtils::tempFile(const char* node, const char* parent,
- bool deleteIfExists) {
+ bool deleteIfExists) {
QByteArray rc(tempDir(parent));
if (!rc.endsWith('/'))
rc += '/';
* @param mode file write mode: "w" (write) or "a" (append)
*/
void ReFileUtils::writeToFile(const char* filename, const char* content,
- size_t contentLength, const char* mode) {
+ size_t contentLength, const char* mode) {
FILE* fp = fopen(filename, mode);
if (fp != NULL) {
if (contentLength == (size_t) - 1)
*/
class ReFileUtils {
public:
- static bool deleteTree(const QString& path, bool withBase, ReLogger* logger);
+ static bool deleteTree(const QString& path, bool withBase,
+ ReLogger* logger);
static bool isAbsolutPath(const QString& path);
static bool isAbsolutPath(const char* path);
+ static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
static int seek(FILE* file, int64_t offset, int whence);
+ static bool setTimes(const char* filename, const QDateTime& modified,
+ const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
static int64_t tell(FILE* file);
static QByteArray tempDir(const char* node, const char* parent = NULL,
- bool withSeparator = true);
+ bool withSeparator = true);
static QByteArray tempFile(const char* node, const char* parent = NULL,
- bool deleteIfExists = true);
- static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
+ bool deleteIfExists = true);
static void writeToFile(const char* filename, const char* content,
- size_t contentLength = (size_t) - 1, const char* mode = "w");
+ size_t contentLength = (size_t) - 1, const char* mode = "w");
+public:
+ static QDateTime m_undefinedTime;
};
#endif // REFILEUTILS_HPP
*/
ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
- bool anchored) :
- m_pattern(),
- m_needles(),
- m_restLengths(),
- m_anchored(anchored),
- m_caseSensivitiy(caseSensivity) {
+ bool anchored) :
+ m_pattern(),
+ m_needles(),
+ m_restLengths(),
+ m_anchored(anchored),
+ m_caseSensivitiy(caseSensivity) {
setPattern(pattern, anchored);
}
bool ReMatcher::matches(const QString& text) {
bool found = m_allMatching || m_needles.size() == 0;
int endIx = m_needles.size() - 1;
- if (! found && m_anchored){
+ if (!found && m_anchored) {
found = m_needles.at(0).size() == 0
- || text.startsWith(m_needles.at(0), m_caseSensivitiy);
- if (found && (endIx > 0 || text.length() != m_pattern.length())){
+ || text.startsWith(m_needles.at(0), m_caseSensivitiy);
+ if (found && (endIx > 0 || text.length() != m_pattern.length())) {
found = m_needles.at(endIx).size() == 0
- || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
+ || text.endsWith(m_needles.at(endIx), m_caseSensivitiy);
}
}
- if (!found || m_anchored && endIx > 1) {
+ if (!found || (m_anchored && endIx > 1)) {
int startIx = 0;
int textIndex = 0;
- if (! m_anchored)
+ if (!m_anchored)
found = true;
else {
startIx++;
for (int ix = startIx; found && ix <= endIx; ix++) {
found = text.size() - textIndex >= m_restLengths.at(ix);
if (found)
- found = (textIndex = text.indexOf(m_needles.at(ix),
- textIndex, m_caseSensivitiy)) >= 0;
+ found = (textIndex = text.indexOf(m_needles.at(ix), textIndex,
+ m_caseSensivitiy)) >= 0;
}
}
return found;
*
* @return the current pattern
*/
-const QString& ReMatcher::pattern() const
-{
+const QString& ReMatcher::pattern() const {
return m_pattern;
}
*
* @return <code>true</code>: the matcher accepts all strings
*/
-bool ReMatcher::allMatching() const
-{
+bool ReMatcher::allMatching() const {
return m_allMatching;
}
*
* @return <code>true</code>: the character case is relevant
*/
-Qt::CaseSensitivity ReMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReMatcher::caseSensivitiy() const {
return m_caseSensivitiy;
}
*
* @param caseSensivitiy <code>true</code>: the character case is relevant
*/
-void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy) {
m_caseSensivitiy = caseSensivitiy;
}
-
/**
* Constructor.
*
* the string
*/
ReListMatcher::ReListMatcher(const QStringList& patterns,
- Qt::CaseSensitivity caseSensivity, bool anchored) :
- m_patterns(patterns),
- m_list(),
- m_empty(false),
- m_allMatching(false)
-{
+ Qt::CaseSensitivity caseSensivity, bool anchored) :
+ m_patterns(patterns),
+ m_list(),
+ m_empty(false),
+ m_allMatching(false) {
setPatterns(patterns, caseSensivity, anchored);
}
/**
- * Destructor.
- */
-ReListMatcher::~ReListMatcher(){
+ * Destructor.
+ */
+ReListMatcher::~ReListMatcher() {
destroy();
}
*
* @return <code>true</code>: the matcher accept all strings
*/
-bool ReListMatcher::allMatching() const
-{
+bool ReListMatcher::allMatching() const {
return m_allMatching;
}
*
* @return a
*/
-const QStringList& ReListMatcher::allMatchingList()
-{
- if (m_allMatchingList == NULL){
+const QStringList& ReListMatcher::allMatchingList() {
+ if (m_allMatchingList == NULL) {
m_allMatchingList = new QStringList();
m_allMatchingList->append("*");
}
*
* @return <code>true</code>: the character case is relevant
*/
-Qt::CaseSensitivity ReListMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReListMatcher::caseSensivitiy() const {
return m_list.at(0)->caseSensivitiy();
}
/**
* Frees the resources.
*/
-void ReListMatcher::destroy(){
+void ReListMatcher::destroy() {
QList<ReMatcher*>::const_iterator it;
- for (it = m_list.constBegin(); it != m_list.cend(); ++it){
+ for (it = m_list.constBegin(); it != m_list.cend(); ++it) {
delete *it;
}
m_list.clear();
*
* @return a matcher accepting all strings
*/
-const ReListMatcher& ReListMatcher::allMatcher()
-{
- if (m_allMatcher == NULL){
+const ReListMatcher& ReListMatcher::allMatcher() {
+ if (m_allMatcher == NULL) {
m_allMatcher = new ReListMatcher(allMatchingList());
}
return *m_allMatcher;
}
-
/**
* Returns the current pattern list.
*
* @return the pattern list
*/
-const QStringList& ReListMatcher::patterns() const
-{
+const QStringList& ReListMatcher::patterns() const {
return m_patterns;
}
*
* @return <code>true</code>: the pattern list is empty
*/
-bool ReListMatcher::empty() const
-{
+bool ReListMatcher::empty() const {
return m_empty;
}
* matches the text<br>
* <code>false</code>: none of the patterns matches
*/
-bool ReListMatcher::matches(const QString& text)
-{
+bool ReListMatcher::matches(const QString& text) {
QList<ReMatcher*>::const_iterator it;
bool rc = m_list.size() == 0;
- for (it = m_list.cbegin(); ! rc && it != m_list.cend(); ++it){
+ for (it = m_list.cbegin(); !rc && it != m_list.cend(); ++it) {
rc = (*it)->matches(text);
}
return rc;
*
* @param caseSensivitiy <code>true</code>: the character case is relevant
*/
-void ReListMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReListMatcher::setCaseSensivitiy(
+ const Qt::CaseSensitivity& caseSensivitiy) {
QList<ReMatcher*>::const_iterator it;
- for (it = m_list.begin(); it != m_list.end(); ++it){
+ for (it = m_list.begin(); it != m_list.end(); ++it) {
(*it)->setCaseSensivitiy(caseSensivitiy);
}
}
* <code>false<code>: the pattern can match anywhere
*/
void ReListMatcher::setPatterns(const QStringList& patterns,
- Qt::CaseSensitivity caseSensivity, bool anchored)
-{
+ Qt::CaseSensitivity caseSensivity, bool anchored) {
destroy();
m_patterns = patterns;
m_empty = true;
m_allMatching = false;
QStringList::const_iterator it;
- for (it = patterns.constBegin(); it != patterns.cend(); ++it){
+ for (it = patterns.constBegin(); it != patterns.cend(); ++it) {
ReMatcher* matcher = new ReMatcher(*it, caseSensivity, anchored);
m_list.append(matcher);
if (matcher->allMatching())
}
}
-
/**
* Constructor.
*
* the string
*/
ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
- const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
- bool anchored) :
- m_includes(includes, caseSensivity, anchored),
- m_excludes(excludes, caseSensivity, anchored)
-{
+ const QStringList& excludes, Qt::CaseSensitivity caseSensivity,
+ bool anchored) :
+ m_includes(includes, caseSensivity, anchored),
+ m_excludes(excludes, caseSensivity, anchored) {
}
/**
*
* @return <code>true</code>: the character case is relevant
*/
-Qt::CaseSensitivity ReIncludeExcludeMatcher::caseSensivitiy() const
-{
+Qt::CaseSensitivity ReIncludeExcludeMatcher::caseSensivitiy() const {
return m_includes.caseSensivitiy();
}
* Returns the exclude matcher.
* @return the exclude matcher
*/
-const ReListMatcher& ReIncludeExcludeMatcher::excludes() const
-{
+const ReListMatcher& ReIncludeExcludeMatcher::excludes() const {
return m_excludes;
}
* Returns the include matcher.
* @return the include matcher
*/
-const ReListMatcher& ReIncludeExcludeMatcher::includes() const
-{
+const ReListMatcher& ReIncludeExcludeMatcher::includes() const {
return m_includes;
}
* @return <code>true</code>: at least one of the include patterns
* matches and none of the exclude patterns matches
*/
-bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo)
-{
+bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo) {
bool rc = m_includes.matches(text);
- if (rc && excludeToo && ! m_excludes.empty())
- rc = ! m_excludes.matches(text);
+ if (rc && excludeToo && !m_excludes.empty())
+ rc = !m_excludes.matches(text);
return rc;
}
*
* @param caseSensivitiy <code>true</code>: the character case is relevant
*/
-void ReIncludeExcludeMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy)
-{
+void ReIncludeExcludeMatcher::setCaseSensivitiy(
+ const Qt::CaseSensitivity& caseSensivitiy) {
m_includes.setCaseSensivitiy(caseSensivitiy);
m_excludes.setCaseSensivitiy(caseSensivitiy);
}
#ifndef REMATCHER_HPP
#define REMATCHER_HPP
-
/**
* Processor for an efficient test whether a text matches a pattern.
*
class ReMatcher {
public:
ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensitivty =
- Qt::CaseSensitive, bool anchored = false);
+ Qt::CaseSensitive, bool anchored = false);
public:
bool allMatching() const;
Qt::CaseSensitivity caseSensivitiy() const;
void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
void setPattern(const QString& pattern, bool anchored = false);
-
protected:
QString m_pattern;
QStringList m_needles;
*/
class ReListMatcher {
public:
- ReListMatcher(const QStringList& patterns, Qt::CaseSensitivity caseSensitivty =
- Qt::CaseSensitive, bool anchored = false);
+ ReListMatcher(const QStringList& patterns,
+ Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored =
+ false);
~ReListMatcher();
public:
bool allMatching() const;
const QStringList& patterns() const;
void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy);
void setPatterns(const QStringList& patterns,
- Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored = false);
+ Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored =
+ false);
public:
static const ReListMatcher& allMatcher();
static const QStringList& allMatchingList();
* Processor for efficient test whether a text matches an include pattern list
* and not an exclude pattern list.
*/
-class ReIncludeExcludeMatcher{
+class ReIncludeExcludeMatcher {
public:
- ReIncludeExcludeMatcher(const QStringList& includes, const QStringList& excludes,
- Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive,
- bool anchored = false);
+ ReIncludeExcludeMatcher(const QStringList& includes,
+ const QStringList& excludes, Qt::CaseSensitivity caseSensitivty =
+ Qt::CaseSensitive, bool anchored = false);
public:
Qt::CaseSensitivity caseSensivitiy() const;
bool matches(const QString& text, bool excludeToo = true);
* otherwise: the length of the integer
*/
int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix,
- quint64* pValue) {
+ quint64* pValue) {
int inputLength = text.size();
int64_t value = 0;
int ix = start;
}
} else {
throw ReException("ReQStringUtil::lengthOfInt(): wrong radix: %d",
- radix);
+ radix);
}
if (pValue != NULL)
*pValue = value;
* otherwise: the length of the integer
*/
int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix,
- uint* pValue) {
+ uint* pValue) {
quint64 value;
int rc = lengthOfUInt64(text, start, radix, &value);
if (pValue != NULL)
* otherwise: the length of the date in the string
*/
int ReQStringUtils::lengthOfDate(const ReString& text, int start,
- QDate* value) {
+ QDate* value) {
uint day = 0;
uint month = 0;
uint year = 0;
}
}
if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1970
- || year > 2100)
+ || year > 2100)
length = 0;
if (length != 0 && value != NULL)
*value = QDate(year, month, day);
* otherwise: the length of the date in the string
*/
int ReQStringUtils::lengthOfDateTime(const ReString& text, int start,
- bool allowDateOnly, bool allowTimeOnly, QDateTime* value) {
+ bool allowDateOnly, bool allowTimeOnly, QDateTime* value) {
QDate date;
QTime time;
int length = lengthOfDate(text, start, &date);
* otherwise: the length of the date in the string
*/
int ReQStringUtils::lengthOfTime(const ReString& text, int start,
- QTime* value) {
+ QTime* value) {
uint hour = 0;
uint minute = 0;
uint sec = 0;
* otherwise: the length of the floating point number
*/
int ReQStringUtils::lengthOfReal(const ReString& text, int start,
- qreal* pValue) {
+ qreal* pValue) {
int inputLength = text.size();
qreal value = 0.0;
int cc;
*/
QString ReQStringUtils::replaceExtension(const QString& path,
- const QString& ext) {
+ const QString& ext) {
QString oldExt = extensionOf(path);
QString rc;
if (oldExt.isEmpty())
* <code>false</code>: unknown name found (not replaced)
*/
bool ReQStringUtils::replacePlaceholders(QString& text,
- const QMap<QString, QString>& placeholders, QString* error) {
+ const QMap<QString, QString>& placeholders, QString* error) {
int start = 0;
bool rc = true;
QString name;
* otherwise: the length is incremented
*/
void ReQStringUtils::skipExpected(const ReString& text, QChar expected,
- int& index, int& length) {
+ int& index, int& length) {
if (length == 0) {
// error state, do nothing
} else if (index >= text.length() || text[index] != expected) {
* @return <code>buffer</code>
*/
char*ReQStringUtils::utf8(const ReString& source, char buffer[],
- size_t bufferSize) {
+ size_t bufferSize) {
QByteArray val = source.toUtf8();
if (val.length() < (int) bufferSize)
bufferSize = val.length() + 1;
class ReParserException: public ReException {
public:
ReParserException(const QString& message) :
- ReException(),
- m_message(message) {
+ ReException(),
+ m_message(message) {
}
public:
QString m_message;
* example: "kibyte:1024;kbyte:1000;mibyte:1048576;mbyte:1000000"
*/
ReUnitParser::ReUnitParser(const QString& expr, const char* unitList,
- bool parseAtOnce) :
- m_result(0),
- m_expr(expr),
- m_message(),
- m_unitList(unitList) {
+ bool parseAtOnce) :
+ m_result(0),
+ m_expr(expr),
+ m_message(),
+ m_unitList(unitList) {
normalize();
if (parseAtOnce)
parse();
// This makes the syntax easier to parse: only one sum operator ('+').
for (int ii = m_expr.length() - 1; ii > 0; ii--) {
if (m_expr[ii] == '-' && m_expr[ii - 1] != '+'
- && m_expr[ii - 1] != '*') {
+ && m_expr[ii - 1] != '*') {
m_expr.insert(ii, '+');
}
}
QStringList powerOperands = it2->split("^");
if (powerOperands.count() > 2)
throw ReParserException(
- QObject::tr(
- "more than 2 power operators, e.g. '2^3^4'"));
+ QObject::tr(
+ "more than 2 power operators, e.g. '2^3^4'"));
QStringList::const_iterator it3 = powerOperands.begin();
QString op = *it3;
bool isNeg = op.startsWith("-");
uint64_t exponent = valueOf(*++it3);
if (qLn(value) * qLn(exponent) >= qLn(qPow(2.0, 64)))
throw ReParserException(
- QObject::tr(
- "number overflow while power operation"));
+ QObject::tr(
+ "number overflow while power operation"));
for (int ii = 1; ii < (int) exponent; ii++)
value = value * fac;
}
QStringList pair = it->split(":");
if (pair.count() == 0)
throw ReParserException(
- QObject::tr(
- "missing ':' in unit definition, e.g. 'k:1000': ")
- + *it);
+ QObject::tr(
+ "missing ':' in unit definition, e.g. 'k:1000': ")
+ + *it);
if (pair.count() > 2)
throw ReParserException(
- QObject::tr("too many ':' in unit definition: ") + *it);
+ QObject::tr("too many ':' in unit definition: ") + *it);
bool ok = false;
QString unit2 = *pair.begin();
QString factor = *++pair.begin();
}
if (!found)
throw ReParserException(
- QObject::tr("unknown unit '$1'. Allowed: ").arg(unit)
- + QString(m_unitList));
+ QObject::tr("unknown unit '$1'. Allowed: ").arg(unit)
+ + QString(m_unitList));
}
return rc;
}
* @param expr an expression, e.g. "10*1024kByte+5MiByte"
*/
ReSizeParser::ReSizeParser(const QString& expr) :
- ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;"
- "mbyte:1000000;mibyte:1048576;"
- "gbyte:1000000000;gibyte:1073741824;"
- "tbyte:1000000000000;tibyte:1099511627776") {
+ ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;"
+ "mbyte:1000000;mibyte:1048576;"
+ "gbyte:1000000000;gibyte:1073741824;"
+ "tbyte:1000000000000;tibyte:1099511627776") {
}
/**
* Constructor.
* @param expr an expression, e.g. "3*3days-5min+3weeks"
*/
ReDateTimeParser::ReDateTimeParser(const QString& expr) :
- ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) {
+ ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) {
parseDateTime(expr);
}
if (m_expr.startsWith("now", Qt::CaseInsensitive)) {
m_expr.remove(0, 3);
} else if ((length2 = ReQStringUtils::lengthOfDateTime(m_expr, 0, true,
- true, &dateTime)) > 0) {
+ true, &dateTime)) > 0) {
rc = dateTime;
m_expr.remove(0, length2);
} else {
}
}
rc.setMSecsSinceEpoch(
- isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
+ isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
m_dateTime = rc;
return rc;
}
static QString& ensureLastChar(QString& value, QChar lastChar);
static ReString extensionOf(const ReString& filename);
static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
- NULL);
+ NULL);
static int lengthOfDateTime(const ReString& text, int start = 0,
- bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value =
- NULL);
+ bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value =
+ NULL);
static int lengthOfReal(const ReString& text, int start = 0, qreal* value =
- NULL);
+ NULL);
static int lengthOfTime(const ReString& text, int start = 0, QTime* value =
- NULL);
+ NULL);
static int lengthOfUInt64(const ReString& text, int start = 0, int radix =
- 10, uint64_t* value = NULL);
+ 10, uint64_t* value = NULL);
static int lengthOfUInt(const ReString& text, int start, int radix,
- uint* pValue);
+ uint* pValue);
static bool match(const QString& heap, const QStringList& needles);
/**
* Returns the path with native path separators.
static QString pathAppend(const QString& base, const QString& path);
static QString replaceExtension(const QString& path, const QString& ext);
static bool replacePlaceholders(QString& text,
- const QMap<QString, QString>& placeholders, QString* error);
+ const QMap<QString, QString>& placeholders, QString* error);
static void skipExpected(const ReString& text, QChar expected, int& index,
- int& length);
+ int& length);
/**
* @brief Returns the value of a hexadecimal digit.
*
*/
inline static int valueOfHexDigit(int digit) {
return digit >= '0' && digit <= '9' ? digit - '0' :
- digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 :
- digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1;
+ digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 :
+ digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1;
}
static char* utf8(const ReString& source, char buffer[], size_t bufferSize);
public:
class ReUnitParser {
public:
ReUnitParser(const QString& expr, const char* unitList, bool parseAtOnce =
- true);
+ true);
public:
bool isValid() const;
const QString& errorMessage() const;
#ifdef __linux__
#include <unistd.h>
+#include <sys/time.h>
#else
#include <io.h>
#include <direct.h>
LOC_REMOVE_1, // 12013
LOC_REMOVE_2, // 12014
LOC_REMOVE_3, // 12015
+ LOC_SET_PROPERTIES_4, // 12016
+ LOC_SET_PROPERTIES_5, // 12017
};
/**
* @param name the name of the filesystem
*/
ReFileSystem::ReFileSystem(const QString& name, ReLogger* logger) :
- m_name(name), m_writeable(false), m_logger(logger), m_buffer(),
- m_blocksize(4*1024*1024), m_undefinedTime()
-{
+ m_name(name),
+ m_writeable(false),
+ m_logger(logger),
+ m_buffer(),
+ m_blocksize(4 * 1024 * 1024),
+ m_undefinedTime() {
}
/**
* Destructor.
*/
-ReFileSystem::~ReFileSystem()
-{
+ReFileSystem::~ReFileSystem() {
}
/**
*
*/
ReFileSystem::ErrorCode ReFileSystem::copy(ReFileMetaData& source,
- ReFileSystem& sourceFS)
-{
+ ReFileSystem& sourceFS) {
int blocksize = min(m_blocksize, sourceFS.blocksize());
ErrorCode rc = EC_SUCCESS;
ErrorCode rc2;
int64_t size = 0;
- while(rc == EC_SUCCESS && size < source.m_size){
- if ( (rc2 = sourceFS.read(source, size, blocksize, m_buffer)) != EC_SUCCESS)
+ while (rc == EC_SUCCESS && size < source.m_size) {
+ if ((rc2 = sourceFS.read(source, size, blocksize, m_buffer))
+ != EC_SUCCESS)
rc = rc2;
- else if ( (rc2 = write(source.m_node, size, m_buffer)) != EC_SUCCESS)
+ else if ((rc2 = write(source.m_node, size, m_buffer)) != EC_SUCCESS)
rc = rc2;
size += blocksize;
}
* @return <code>true</code>: modification in the filesystem are possible
* <code>false</code>: read only filesystem
*/
-bool ReFileSystem::writeable() const
-{
+bool ReFileSystem::writeable() const {
return m_writeable;
}
*
* @param writeable <code>true</code>: the filesystem is writeable
*/
-void ReFileSystem::setWriteable(bool writeable)
-{
+void ReFileSystem::setWriteable(bool writeable) {
m_writeable = writeable;
}
/**
*
* @return the current blocksize
*/
-int ReFileSystem::blocksize() const
-{
+int ReFileSystem::blocksize() const {
return m_blocksize;
}
* @return <code>true</code>: at least one file found<br>
* <code>false</code>: no file found
*/
-bool ReFileSystem::first(const QString& pattern, ReFileMetaData& file)
-{
+bool ReFileSystem::first(const QString& pattern, ReFileMetaData& file) {
ReFileMetaDataList list;
QStringList names;
names.append(pattern);
- ReIncludeExcludeMatcher matcher(names,
- ReQStringUtils::m_emptyList, Qt::CaseInsensitive, true);
+ ReIncludeExcludeMatcher matcher(names, ReQStringUtils::m_emptyList,
+ Qt::CaseInsensitive, true);
listInfos(matcher, list);
bool rc = list.size() > 0;
if (rc)
*
* @param blocksize the new blocksize
*/
-void ReFileSystem::setBlocksize(int blocksize)
-{
+void ReFileSystem::setBlocksize(int blocksize) {
m_blocksize = blocksize;
}
-
/**
* Constructor.
*
* @param logger
*/
ReLocalFileSytem::ReLocalFileSytem(const QString& basePath, ReLogger* logger) :
- ReFileSystem("localfs", logger),
- m_basePath(basePath),
- m_currentPath(basePath),
- m_dir(basePath),
- m_readFile(NULL),
- m_writeFile(NULL)
-{
+ ReFileSystem("localfs", logger),
+ m_basePath(basePath),
+ m_currentPath(basePath),
+ m_dir(basePath),
+ m_readFile(NULL),
+ m_writeFile(NULL) {
setWriteable(true);
}
/**
* Destructor.
*/
-ReLocalFileSytem::~ReLocalFileSytem()
-{
+ReLocalFileSytem::~ReLocalFileSytem() {
}
*
* @return the base path
*/
-const QString& ReLocalFileSytem::basePath() const
-{
+const QString& ReLocalFileSytem::basePath() const {
return m_basePath;
}
/**
* Closes the open files.
*/
-void ReLocalFileSytem::close()
-{
- if (m_readFile != NULL){
+void ReLocalFileSytem::close() {
+ if (m_readFile != NULL) {
fclose(m_readFile);
m_readFile = NULL;
}
- if (m_writeFile != NULL){
+ if (m_writeFile != NULL) {
fclose(m_writeFile);
m_writeFile = NULL;
}
*
* @return the name of the current directory
*/
-const QString& ReLocalFileSytem::directory() const
-{
+const QString& ReLocalFileSytem::directory() const {
return m_currentPath;
}
* @return the count of the found entries (<code>list.size()</code>)
*/
int ReLocalFileSytem::listInfos(const ReIncludeExcludeMatcher& matcher,
- ReFileMetaDataList& list)
-{
+ ReFileMetaDataList& list) {
list.clear();
const QStringList& patterns = matcher.includes().patterns();
- QStringList nodes = patterns.size() == 0 ? m_dir.entryList()
- : m_dir.entryList(patterns);
+ QStringList nodes =
+ patterns.size() == 0 ? m_dir.entryList() : m_dir.entryList(patterns);
QStringList::const_iterator it;
QByteArray full = m_currentPath.toUtf8();
full.append(OS_SEPARATOR);
int pathLength = full.length();
struct stat info;
- for (it = nodes.cbegin(); it != nodes.cend(); it++){
+ for (it = nodes.cbegin(); it != nodes.cend(); it++) {
QString node = *it;
full.resize(pathLength);
full.append(node.toUtf8());
- if (stat(full.constData(), &info) == 0){
- list.append(ReFileMetaData(node,
- QDateTime::fromTime_t(info.st_mtime),
- QDateTime::fromTime_t(info.st_ctime),
- info.st_uid, info.st_gid, info.st_mode, info.st_size));
+ if (stat(full.constData(), &info) == 0) {
+ list.append(
+ ReFileMetaData(node, QDateTime::fromTime_t(info.st_mtime),
+ QDateTime::fromTime_t(info.st_ctime), info.st_uid,
+ info.st_gid, info.st_mode, info.st_size));
}
}
return list.size();
* EC_ALREADY_EXISTS: a file with this name exists<br>
* EC_NOT_ACCESSIBLE: creation failed
*/
-ReFileSystem::ErrorCode ReLocalFileSytem::makeDir(const QString& node)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::makeDir(const QString& node) {
ErrorCode rc = EC_SUCCESS;
- if (! m_writeable){
- m_logger->log(LOG_ERROR, LOC_MAKE_DIR_1,
- "filesystem is readonly");
+ if (!m_writeable) {
+ m_logger->log(LOG_ERROR, LOC_MAKE_DIR_1, "filesystem is readonly");
rc = EC_FS_READ_ONLY;
} else if (m_dir.exists(node)) {
- m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2,
- "node exists already: %s", fullNameAsUTF8(node).constData());
+ m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2, "node exists already: %s",
+ fullNameAsUTF8(node).constData());
rc = EC_ALREADY_EXISTS;
- } else if (! m_dir.mkdir(node)){
- m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2,
- "cannot create directory: %s", fullNameAsUTF8(node).constData());
+ } else if (!m_dir.mkdir(node)) {
+ m_logger->logv(LOG_ERROR, LOC_MAKE_DIR_2, "cannot create directory: %s",
+ fullNameAsUTF8(node).constData());
rc = EC_NOT_ACCESSIBLE;
}
return rc;
* EC_PATH_NOT_FOUND directory does not exist<br>
* EC_NOT_ACCESSIBLE parent not readable
*/
-ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path) {
ErrorCode rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND;
m_currentPath = m_dir.absolutePath();
return rc;
* EC_READ: error while reading
*/
ReFileSystem::ErrorCode ReLocalFileSytem::read(const ReFileMetaData& source,
- int64_t offset, int size, QByteArray& buffer)
-{
+ int64_t offset, int size, QByteArray& buffer) {
ErrorCode rc = EC_SUCCESS;
- if (offset == 0){
+ if (offset == 0) {
if (m_readFile != NULL)
fclose(m_readFile);
QString fn = m_currentPath + source.m_node;
- if ( (m_readFile = fopen(fn.toUtf8().constData(), "rb")) == NULL){
+ if ((m_readFile = fopen(fn.toUtf8().constData(), "rb")) == NULL) {
m_logger->logv(LOG_ERROR, LOC_READ_1,
- "cannot open for reading (%d): %s",
- errno, fn.toUtf8().constData());
+ "cannot open for reading (%d): %s", errno,
+ fn.toUtf8().constData());
rc = EC_NOT_READABLE;
}
}
- if (m_readFile != NULL){
+ if (m_readFile != NULL) {
ReFileUtils::seek(m_readFile, offset, SEEK_SET);
buffer.reserve(size);
int nRead = fread(buffer.data(), 1, size, m_readFile);
- if (nRead < 0){
- m_logger->logv(LOG_ERROR, LOC_READ_2,
- "cannot read (%d): %s",
- errno, source.m_node.toUtf8().constData());
+ if (nRead < 0) {
+ m_logger->logv(LOG_ERROR, LOC_READ_2, "cannot read (%d): %s", errno,
+ source.m_node.toUtf8().constData());
nRead = 0;
rc = EC_READ;
}
buffer.resize(nRead);
- if (feof(m_readFile)){
+ if (feof(m_readFile)) {
fclose(m_readFile);
m_readFile = NULL;
} else {
return rc;
}
-/**
- * Sets the properties of a file in the current directory.
- *
- * @param source the properties to copy
- * @param target the properties of the file to change
- * @return EC_SUCCESS: successful<br>
- * EC_FS_READ_ONLY: filesystem is readonly<br>
- * EC_ALREADY_EXISTS: renaming failed: target node exists already<br>
- * EC_RENAME: renaming failed
- *
- */
-ReFileSystem::ErrorCode ReLocalFileSytem::setProperties(
- const ReFileMetaData& source, const ReFileMetaData& target)
-{
- ErrorCode rc = EC_SUCCESS;
- if (! m_writeable){
- m_logger->log(LOG_ERROR, LOC_SET_PROPERTIES_1,
- "filesystem is readonly");
- rc = EC_FS_READ_ONLY;
- } else {
- if (target.m_node != source.m_node){
- if (m_dir.exists(source.m_node)){
- rc = EC_ALREADY_EXISTS;
- m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_2,
- "renaming impossible: node exists: %s",
- fullNameAsUTF8(target.m_node).constData());
- } else if (! m_dir.rename(target.m_node, source.m_node)){
- rc = EC_RENAME;
- m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_3,
- "renaming impossible: %s -> %s",
- source.m_node.toUtf8().constData(),
- fullNameAsUTF8(target.m_node).constData());
- }
- }
- if (rc == EC_SUCCESS && source.m_modified != target.m_modified
- && source.m_modified != m_undefinedTime){
- }
- if (rc == EC_SUCCESS && source.m_created != target.m_created
- && source.m_created != m_undefinedTime){
- }
- if (rc == EC_SUCCESS && source.m_mode != target.m_mode
- && source.m_mode != (mode_t) -1){
- }
- if (rc == EC_SUCCESS && source.m_owner != target.m_owner
- && source.m_owner != -1){
- }
- if (rc == EC_SUCCESS && source.m_group != target.m_group
- && source.m_group != -1){
- }
- }
- return rc;
-}
-
/**
* Removes a file or directory.
*
* EC_NOT_ACCESSIBLE: removing failed
*
*/
-ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node)
-{
+ReFileSystem::ErrorCode ReLocalFileSytem::remove(const ReFileMetaData& node) {
ErrorCode rc = EC_SUCCESS;
- if (! m_writeable){
- m_logger->log(LOG_ERROR, LOC_REMOVE_1,
- "filesystem is readonly");
+ if (!m_writeable) {
+ m_logger->log(LOG_ERROR, LOC_REMOVE_1, "filesystem is readonly");
rc = EC_FS_READ_ONLY;
- } else if (! m_dir.exists(node.m_node)) {
- m_logger->logv(LOG_ERROR, LOC_REMOVE_2,
- "node does not exists: %s", fullNameAsUTF8(node.m_node).constData());
+ } else if (!m_dir.exists(node.m_node)) {
+ m_logger->logv(LOG_ERROR, LOC_REMOVE_2, "node does not exists: %s",
+ fullNameAsUTF8(node.m_node).constData());
rc = EC_NOT_EXISTS;
} else {
- if (S_ISDIR(node.m_mode)){
- if (! m_dir.rmdir(node.m_node)){
+ if (S_ISDIR(node.m_mode)) {
+ if (!m_dir.rmdir(node.m_node)) {
m_logger->logv(LOG_ERROR, LOC_REMOVE_3,
- "cannot remove directory: %s", fullNameAsUTF8(node.m_node).constData());
+ "cannot remove directory: %s",
+ fullNameAsUTF8(node.m_node).constData());
rc = EC_NOT_ACCESSIBLE;
}
} else {
- if (! m_dir.remove(node.m_node)){
+ if (!m_dir.remove(node.m_node)) {
m_logger->logv(LOG_ERROR, LOC_REMOVE_3,
- "cannot remove file: %s", fullNameAsUTF8(node.m_node).constData());
+ "cannot remove file: %s",
+ fullNameAsUTF8(node.m_node).constData());
rc = EC_NOT_ACCESSIBLE;
}
}
return rc;
}
+/**
+ * Sets the properties of a file in the current directory.
+ *
+ * @param source the properties to copy
+ * @param target the properties of the file to change
+ * @return EC_SUCCESS: successful<br>
+ * EC_FS_READ_ONLY: filesystem is readonly<br>
+ * EC_ALREADY_EXISTS: renaming failed: target node exists already<br>
+ * EC_RENAME: renaming failed
+ *
+ */
+ReFileSystem::ErrorCode ReLocalFileSytem::setProperties(
+ const ReFileMetaData& source, const ReFileMetaData& target) {
+ ErrorCode rc = EC_SUCCESS;
+ if (!m_writeable) {
+ m_logger->log(LOG_ERROR, LOC_SET_PROPERTIES_1,
+ "filesystem is readonly");
+ rc = EC_FS_READ_ONLY;
+ } else
+ do {
+ if (target.m_node != source.m_node) {
+ if (m_dir.exists(source.m_node)) {
+ rc = EC_ALREADY_EXISTS;
+ m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_2,
+ "renaming impossible: node exists: %s",
+ fullNameAsUTF8(target.m_node).constData());
+ break;
+ } else if (!m_dir.rename(target.m_node, source.m_node)) {
+ rc = EC_RENAME;
+ m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_3,
+ "renaming impossible: %s -> %s",
+ source.m_node.toUtf8().constData(),
+ fullNameAsUTF8(target.m_node).constData());
+ break;
+ }
+ }
+ QByteArray name;
+ if (source.m_modified != target.m_modified
+ && source.m_modified != ReFileUtils::m_undefinedTime) {
+ if (name.length() == 0)
+ name = fullNameAsUTF8(target.m_node);
+ if (!ReFileUtils::setTimes(name.constData(), source.m_modified,
+ ReFileUtils::m_undefinedTime, m_logger))
+ rc = EC_NOT_ACCESSIBLE;
+
+ }
+#ifdef __linux__
+ if (source.m_mode != target.m_mode
+ && source.m_mode != (mode_t) -1) {
+ if (chmod(name.constData(), source.m_mode) != 0) {
+ rc = EC_NOT_ACCESSIBLE;
+ m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_4,
+ "changing permissions is impossible: %s",
+ name.constData());}
+ }
+ if ( (source.m_owner != target.m_owner
+ && source.m_owner != -1)
+ || (source.m_group != source.m_group
+ && source.m_group != -1)) {
+ int uid = source.m_owner == -1 ? target.m_owner : source.m_owner;
+ int gid = source.m_group == -1 ? target.m_group : source.m_group;
+ if (name.length() == 0)
+ name = fullNameAsUTF8(target.m_node);
+ if (chown(name.constData(), uid, gid) != 0) {
+ rc = EC_NOT_ACCESSIBLE;
+ m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_5,
+ "changing owner/group is impossible: %s",
+ name.constData());
+ }
+ }
+#endif
+ } while (false);
+ return rc;
+}
+
/**
* Writes a buffer to a file.
*
*
*/
ReFileSystem::ErrorCode ReLocalFileSytem::write(const QString& node,
- int64_t offset, const QByteArray& buffer)
-{
+ int64_t offset, const QByteArray& buffer) {
ErrorCode rc = EC_SUCCESS;
- if (! writeable()){
- m_logger->log(LOG_ERROR, LOC_WRITE_1,
- "filesystem is readonly");
+ if (!writeable()) {
+ m_logger->log(LOG_ERROR, LOC_WRITE_1, "filesystem is readonly");
rc = EC_FS_READ_ONLY;
} else {
- if (offset == 0){
+ if (offset == 0) {
if (m_writeFile != NULL)
fclose(m_writeFile);
QString fn = m_currentPath + node;
- if ( (m_writeFile = fopen(fn.toUtf8().constData(), "wb")) == NULL){
+ if ((m_writeFile = fopen(fn.toUtf8().constData(), "wb")) == NULL) {
m_logger->logv(LOG_ERROR, LOC_WRITE_2,
- "cannot open for writing (%d): %s",
- errno, fn.toUtf8().constData());
+ "cannot open for writing (%d): %s", errno,
+ fn.toUtf8().constData());
rc = EC_NOT_WRITEABLE;
}
}
- if (m_writeFile != NULL){
+ if (m_writeFile != NULL) {
int64_t position = ReFileUtils::tell(m_writeFile);
- if (position != offset){
+ if (position != offset) {
rc = EC_POSITION;
m_logger->logv(LOG_ERROR, LOC_WRITE_4,
- "wrong file position: %lld/%lld",
- offset, position);
+ "wrong file position: %lld/%lld", offset, position);
} else {
- int nWritten = fwrite(buffer.constData(),
- 1, buffer.length(), m_writeFile);
- if (nWritten != buffer.length()){
+ int nWritten = fwrite(buffer.constData(), 1, buffer.length(),
+ m_writeFile);
+ if (nWritten != buffer.length()) {
m_logger->logv(LOG_ERROR, LOC_WRITE_3,
- "cannot write (%d): %s written: %d/%d",
- errno, node.toUtf8().constData(),
- nWritten, buffer.length());
+ "cannot write (%d): %s written: %d/%d", errno,
+ node.toUtf8().constData(), nWritten, buffer.length());
rc = EC_WRITE;
}
fflush(m_writeFile);
return rc;
}
-
/**
* Constructor.
*/
-ReFileMetaData::ReFileMetaData() : m_node(), m_modified(), m_created(),
- m_owner(0), m_group(0), m_mode(0), m_size(-1){
+ReFileMetaData::ReFileMetaData() :
+ m_node(),
+ m_modified(),
+ m_created(),
+ m_owner(-1),
+ m_group(-1),
+ m_mode(-1),
+ m_size(-1) {
}
* @param size the filesize (0 for directories)
*/
ReFileMetaData::ReFileMetaData(const QString& node, const QDateTime& modified,
- const QDateTime& created, int owner, int group, mode_t mode,
- int64_t size) :
- m_node(node),
- m_modified(modified),
- m_created(created),
- m_owner(owner),
- m_group(group),
- m_mode(mode),
- m_size(size)
-{
+ const QDateTime& created, int owner, int group, mode_t mode, int64_t size) :
+ m_node(node),
+ m_modified(modified),
+ m_created(created),
+ m_owner(owner),
+ m_group(group),
+ m_mode(mode),
+ m_size(size) {
}
/**
* Destructor.
*/
-ReFileMetaData::~ReFileMetaData()
-{
+ReFileMetaData::~ReFileMetaData() {
}
/**
* @param source source to copy
*/
ReFileMetaData::ReFileMetaData(const ReFileMetaData& source) :
- m_node(source.m_node),
- m_modified(source.m_modified),
- m_created(source.m_created),
- m_owner(source.m_owner),
- m_group(source.m_group),
- m_mode(source.m_mode),
- m_size(source.m_size)
-{
+ m_node(source.m_node),
+ m_modified(source.m_modified),
+ m_created(source.m_created),
+ m_owner(source.m_owner),
+ m_group(source.m_group),
+ m_mode(source.m_mode),
+ m_size(source.m_size) {
}
* @param source source to copy
* @return the instance itself
*/
-ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source)
-{
+ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source) {
m_node = source.m_node;
m_modified = source.m_modified;
m_created = source.m_created;
public:
ReFileMetaData();
ReFileMetaData(const QString& node, const QDateTime& modified,
- const QDateTime& created,
- int owner, int group, mode_t mode, int64_t size);
+ const QDateTime& created, int owner, int group, mode_t mode,
+ int64_t size);
virtual ~ReFileMetaData();
ReFileMetaData(const ReFileMetaData& source);
ReFileMetaData& operator =(const ReFileMetaData& source);
* @return the count of the found entries (<code>list.size()</code>)
*/
virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
- ReFileMetaDataList& list) = 0;
+ ReFileMetaDataList& list) = 0;
/** Creates a directory.
* @param node the name without path (in the current directory)
* @return EC_SUCCESS or error code
* @param buffer OUT: content of the file
* @return EC_SUCCESS or error code
*/
- virtual ErrorCode read(const ReFileMetaData& source,
- int64_t offset, int size,
- QByteArray& buffer) = 0;
+ virtual ErrorCode read(const ReFileMetaData& source, int64_t offset,
+ int size, QByteArray& buffer) = 0;
/** Removes a file or directory.
* @param node the properties ot the node (in the current directory)
* @return EC_SUCCESS or error code
* @return EC_SUCCESS or error code
*/
virtual ErrorCode setProperties(const ReFileMetaData& source,
- const ReFileMetaData& target) = 0;
+ const ReFileMetaData& target) = 0;
/** Writes a buffer to a file.
* @param node the file to write (without path, inside the current directory)
* @param offset first position to write
* @param buffer content to write
* @return EC_SUCCESS or error code
*/
- virtual ErrorCode write(const QString& target,
- int64_t offset, const QByteArray& buffer) = 0;
+ virtual ErrorCode write(const QString& target, int64_t offset,
+ const QByteArray& buffer) = 0;
public:
virtual ErrorCode copy(ReFileMetaData& source, ReFileSystem& sourceFS);
public:
* @param node the name without path
* @return the full filename
*/
- inline QString fullName(const QString& node) const{
+ inline QString fullName(const QString& node) const {
return m_directory + node;
}
/** Returns the full name (with path) as UTF-8 string.
* @param node the name without path
* @return the full filename
*/
- QByteArray fullNameAsUTF8(const QString& node) const{
+ QByteArray fullNameAsUTF8(const QString& node) const {
return (m_directory + node).toUtf8();
}
void setWriteable(bool writeable);
QDateTime m_undefinedTime;
};
-class ReLocalFileSytem : public ReFileSystem {
+class ReLocalFileSytem: public ReFileSystem {
public:
ReLocalFileSytem(const QString& basePath, ReLogger* logger);
virtual ~ReLocalFileSytem();
// ReFileSystem interface
virtual void close();
virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
- ReFileMetaDataList& list);
+ ReFileMetaDataList& list);
ErrorCode makeDir(const QString& node);
virtual ErrorCode read(const ReFileMetaData& source, int64_t offset,
- int size, QByteArray& buffer);
+ int size, QByteArray& buffer);
ErrorCode remove(const ReFileMetaData& node);
- ErrorCode setProperties(const ReFileMetaData& source, const ReFileMetaData& target);
+ ErrorCode setProperties(const ReFileMetaData& source,
+ const ReFileMetaData& target);
virtual ErrorCode write(const QString& target, int64_t offset,
- const QByteArray& buffer);
+ const QByteArray& buffer);
protected:
QString m_basePath;