From 44aec8348ba051c609b3060f23a55d38a7a8bd19 Mon Sep 17 00:00:00 2001 From: hama Date: Sun, 25 Oct 2015 23:05:36 +0100 Subject: [PATCH] ReCharSet, ReCryptFileSystem * new ReCharSet * implementation of ReCryptFileSystem --- .cproject | 43 ++++++------- base/ReMatcher.cpp | 60 +++++++++++------- base/ReMatcher.hpp | 19 +++--- base/ReStringUtils.cpp | 111 ++++++++++++++++++++++++++++++++++ base/ReStringUtils.hpp | 26 ++++++++ cunit/allTests.cpp | 2 + cunit/cuReCryptFileSystem.cpp | 107 ++++++++++++++++++++++++++++++++ cunit/cuReFileSystem.cpp | 32 ++++++++++ cunit/cunit.pro | 12 ++-- os/ReCryptFileSystem.cpp | 21 ++++++- os/ReCryptFileSystem.hpp | 3 +- os/ReFileSystem.cpp | 52 ++++++++++++++++ os/ReFileSystem.hpp | 18 +++++- 13 files changed, 442 insertions(+), 64 deletions(-) create mode 100644 cunit/cuReCryptFileSystem.cpp diff --git a/.cproject b/.cproject index 427ca30..bed0e56 100644 --- a/.cproject +++ b/.cproject @@ -1,54 +1,45 @@ - - + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + - diff --git a/base/ReMatcher.cpp b/base/ReMatcher.cpp index cae8662..7d46812 100644 --- a/base/ReMatcher.cpp +++ b/base/ReMatcher.cpp @@ -22,7 +22,7 @@ QStringList* ReListMatcher::m_allMatchingList = NULL; ReListMatcher* ReListMatcher::m_allMatcher = NULL; - +ReIncludeExcludeMatcher* ReIncludeExcludeMatcher::m_allMatcher = NULL; /** * Constructor. * @@ -35,12 +35,12 @@ ReListMatcher* ReListMatcher::m_allMatcher = NULL; */ 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); } @@ -55,10 +55,10 @@ bool ReMatcher::matches(const QString& text) { int endIx = m_needles.size() - 1; if (!found && m_anchored) { found = m_needles.at(0).size() == 0 - || text.startsWith(m_needles.at(0), m_caseSensivitiy); + || 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)) { @@ -75,7 +75,7 @@ bool ReMatcher::matches(const QString& text) { found = text.size() - textIndex >= m_restLengths.at(ix); if (found) found = (textIndex = text.indexOf(m_needles.at(ix), textIndex, - m_caseSensivitiy)) >= 0; + m_caseSensivitiy)) >= 0; } } return found; @@ -159,11 +159,11 @@ void ReMatcher::setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy) { * 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); } /** @@ -267,7 +267,7 @@ bool ReListMatcher::matches(const QString& text) { * @param caseSensivitiy true: the character case is relevant */ void ReListMatcher::setCaseSensivitiy( - const Qt::CaseSensitivity& caseSensivitiy) { + const Qt::CaseSensitivity& caseSensivitiy) { QList::const_iterator it; for (it = m_list.begin(); it != m_list.end(); ++it) { (*it)->setCaseSensivitiy(caseSensivitiy); @@ -282,7 +282,7 @@ void ReListMatcher::setCaseSensivitiy( * false: 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; @@ -309,10 +309,26 @@ void ReListMatcher::setPatterns(const QStringList& patterns, * 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) { +} + +/** + * Returns the singleton instance of a matcher matching all strings. + * + * @return a matcher matching all strings + */ +const ReIncludeExcludeMatcher& ReIncludeExcludeMatcher::allMatcher() +{ + if (m_allMatcher == NULL){ + QStringList includes; + includes.append("*"); + QStringList excludes; + m_allMatcher = new ReIncludeExcludeMatcher(includes, excludes); + } + return *m_allMatcher; } /** @@ -362,7 +378,7 @@ bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo) { * @param caseSensivitiy true: the character case is relevant */ void ReIncludeExcludeMatcher::setCaseSensivitiy( - const Qt::CaseSensitivity& caseSensivitiy) { + const Qt::CaseSensitivity& caseSensivitiy) { m_includes.setCaseSensivitiy(caseSensivitiy); m_excludes.setCaseSensivitiy(caseSensivitiy); } diff --git a/base/ReMatcher.hpp b/base/ReMatcher.hpp index e89c888..c26e87f 100644 --- a/base/ReMatcher.hpp +++ b/base/ReMatcher.hpp @@ -20,7 +20,7 @@ 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; @@ -45,8 +45,8 @@ protected: class ReListMatcher { public: ReListMatcher(const QStringList& patterns, - Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored = - false); + Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored = + false); ~ReListMatcher(); public: bool allMatching() const; @@ -56,8 +56,8 @@ public: 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(); @@ -80,15 +80,18 @@ protected: class ReIncludeExcludeMatcher { public: ReIncludeExcludeMatcher(const QStringList& includes, - const QStringList& excludes, Qt::CaseSensitivity caseSensitivty = - Qt::CaseSensitive, bool anchored = false); + const QStringList& excludes, Qt::CaseSensitivity caseSensitivty = + Qt::CaseSensitive, bool anchored = false); public: Qt::CaseSensitivity caseSensivitiy() const; bool matches(const QString& text, bool excludeToo = true); const ReListMatcher& includes() const; const ReListMatcher& excludes() const; void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy); - +public: + static const ReIncludeExcludeMatcher& allMatcher(); +private: + static ReIncludeExcludeMatcher* m_allMatcher; protected: ReListMatcher m_includes; ReListMatcher m_excludes; diff --git a/base/ReStringUtils.cpp b/base/ReStringUtils.cpp index 03e57e7..d01b4c1 100644 --- a/base/ReStringUtils.cpp +++ b/base/ReStringUtils.cpp @@ -540,3 +540,114 @@ int ReStringUtils::lengthOfReal(const char* text, qreal* pValue) { return found ? length : 0; } +/** + * Constructor. + * + * @param charOf a string containing all member characters of the char set. + * @param indexOf an array containing the index of the char at the position + * of the char, starting with the minimum character + * @param count -1: strlen(charOf) is taken
+ * + * otherwise: the length of charOf[] + */ +ReCharSet::ReCharSet(const char* charOf, int* indexOf, + char minChar, char maxChar, int count) : + m_count(count < 0 ? strlen(charOf) : count), + m_minChar(minChar), + m_maxChar(maxChar), + m_charOf(charOf), + m_indexOf(indexOf), + m_ownsCharOf(false) +{ + if (minChar == 0 && maxChar == 0) + getMinMax(m_charOf, m_minChar, m_maxChar); + if (indexOf == NULL){ + int length = m_maxChar - m_minChar + 1; + m_indexOf = new int[length]; + m_ownsCharOf = true; + fillIndexOf(m_charOf, m_minChar, m_maxChar, m_indexOf, + length * sizeof *m_indexOf); + } +} + +/** + * Writes the definition of indexOf into a string. + * + * @return the indexOf array as C text + */ +QByteArray ReCharSet::dumpIndexOf(){ + QByteArray rc; + int length = m_maxChar - m_minChar + 1; + rc.reserve(100 + length * 10); + rc.append("// minChar = ").append(QByteArray::number(m_minChar)).append('\n'); + rc.append("// maxChar = ").append(QByteArray::number(m_maxChar)).append('\n'); + rc.append("int* indexOf[] = {\n"); + for (int ix = 0; ix < length; ix++){ + rc.append(QString::number(m_indexOf[ix])).append(','); + if (m_indexOf[ix] >= 0) + rc.append("\t// '").append(m_charOf[m_indexOf[ix]]).append('\''); + rc.append('\n'); + } + rc.append("};\n"); + return rc; +} + +/** + * Finds the minimum and the maximum char of an ascii string. + * + * The minimum of "badc" is 'a', the maximum is 'd'. + * + * @param charSet a string with the characters to inspect + * @param minChar OUT: the minimum character + * @param maxChar OUT: the maximum character + */ +void ReCharSet::getMinMax(const char* charSet, char& minChar, char& maxChar) +{ + minChar = maxChar = charSet[0]; + while(*charSet != '\0'){ + if (*charSet < minChar) + minChar = *charSet; + else if (*charSet > maxChar) + maxChar = *charSet; + ++charSet; + } +} + +/** + * Calculates the indexOf table from the character set. + * + * Invalid character positions will be set to -1. + * For all valid characters of the set is: + * assert(indexOf[charset[ix] - minChar] == ix + * && charSet[indexOf[cc - minChar] == cc) + * + * @param charSet the character set + * @param minChar the character of the set with the minimal value: + * If 0 and maxChar == 0: the values will be calculated + * @param maxChar the character of the set with the maximal value + * @param indexOf OUT: the table to fill + * @param sizeIndexOf the size of indexOf + * @return true: success
+ * false: minChar or maxChar invalid or wrong size + */ +bool ReCharSet::fillIndexOf(const char* charSet, char minChar, char maxChar, + int* indexOf, size_t sizeIndexOf) +{ + bool rc = true; + int length = maxChar - minChar + 1; + if (length != sizeIndexOf / sizeof*indexOf) + rc = false; + else { + int ix = 0; + memset(indexOf, -1, sizeIndexOf); + while(*charSet != '\0'){ + char cc = *charSet++; + if (cc < minChar || cc > maxChar) + rc = false; + else + indexOf[cc - minChar] = ix; + ix++; + } + } + return rc; +} diff --git a/base/ReStringUtils.hpp b/base/ReStringUtils.hpp index dfcf76c..26e54a7 100644 --- a/base/ReStringUtils.hpp +++ b/base/ReStringUtils.hpp @@ -11,6 +11,32 @@ #ifndef RPLSTRING_HPP #define RPLSTRING_HPP +class ReCharSet { +public: + ReCharSet(const char* indexToChar, int* charToIndex, + char minChar = 0, char maxChar = 0, int count = -1); +public: + inline char charOf(int index){ + return index >= 0 && index < m_count ? m_charOf[index] : 0; + } + inline char indexOf(char cc){ + return cc < m_minChar || cc > m_maxChar ? -1 : m_indexOf[cc - m_minChar]; + } + QByteArray dumpIndexOf(); + +public: + static void getMinMax(const char* charSet, char& minChar, char& maxChar); + static bool fillIndexOf(const char* charSet, char minChar, char maxChar, + int* indexOf, size_t sizeIndexOf); +protected: + int m_count; + char m_minChar; + char m_maxChar; + const char* m_charOf; + int* m_indexOf; + bool m_ownsCharOf; +}; + class ReStringUtils { public: static int countChar(const char* line, char cc); diff --git a/cunit/allTests.cpp b/cunit/allTests.cpp index dfef20a..dbfea14 100644 --- a/cunit/allTests.cpp +++ b/cunit/allTests.cpp @@ -88,7 +88,9 @@ static void testNet() { } static void testOs() { void testReFileSystem(); + void testReCryptFileSystem(); + testReCryptFileSystem(); testReFileSystem(); } void allTests() { diff --git a/cunit/cuReCryptFileSystem.cpp b/cunit/cuReCryptFileSystem.cpp new file mode 100644 index 0000000..f163648 --- /dev/null +++ b/cunit/cuReCryptFileSystem.cpp @@ -0,0 +1,107 @@ +/* + * cuReCryptFileSystem.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ +#include "base/rebase.hpp" +#include "os/reos.hpp" + +/** @file + * @brief Unit test of the basic exceptions. + */ + +class MyReCryptFileSystem : private ReCryptFileSystem, private ReTest { +public: + MyReCryptFileSystem(ReLocalFileSystem& hostFs, ReRandomizer& random, + ReLogger* logger) : + ReCryptFileSystem(hostFs, random, logger), + ReTest("MyReCryptFileSystem") + { + } +public: + virtual void run(void){ + log("run"); + } + + void testRead(){ + readMetaFile(); + ReFileMetaDataList list; + checkEqu(3, listInfos(ReIncludeExcludeMatcher::allMatcher(), list)); + ReFileMetaData entry = list.at(0); + checkEqu("Homunculus.txt", entry.m_node); + entry = list.at(1); + checkEqu("NewYork.png", entry.m_node); + entry = list.at(2); + checkEqu("tiger.in.india.mov", entry.m_node); + } + void testWrite(){ + addFile("Homunculus.txt"); + addFile("NewYork.png"); + addFile("tiger.in.india.mov"); + writeMetaFile(); + } + +}; + +class TestReCryptFileSystem: public ReTest { +public: + TestReCryptFileSystem() : + ReTest("ReCryptFileSystem"), + m_sourceBase(), + m_hostBase(), + m_sourceFs(NULL), + m_hostFs(NULL), + m_cryptFs(NULL) + { + doIt(); + } + ~TestReCryptFileSystem(){ + destroy(); + } + +private: + QByteArray m_sourceBase; + QByteArray m_hostBase; + ReLocalFileSystem* m_sourceFs; + ReLocalFileSystem* m_hostFs; + ReCryptFileSystem* m_cryptFs; + ReKISSRandomizer m_contentRandom; +protected: + void init() { + m_hostBase = ReFileUtils::tempDir("cryptfs"); + m_sourceBase = ReFileUtils::tempDir("sourcefs"); + m_hostFs = new ReLocalFileSystem(m_hostBase, &m_logger); + m_cryptFs = new ReCryptFileSystem(*m_hostFs, m_contentRandom, &m_logger); + } + void destroy(){ + delete m_sourceFs; + delete m_hostFs; + delete m_cryptFs; + m_sourceFs = NULL; + m_hostFs = NULL; + m_cryptFs = NULL; + } + void testWriteRead(){ + MyReCryptFileSystem cryptFs1(*m_hostFs, m_contentRandom, &m_logger); + cryptFs1.testWrite(); + + MyReCryptFileSystem cryptFs2(*m_hostFs, m_contentRandom, &m_logger); + cryptFs2.testRead(); + + + } + + virtual void run() { + init(); + testWriteRead(); + } +}; +void testReCryptFileSystem() { + TestReCryptFileSystem test; +} + diff --git a/cunit/cuReFileSystem.cpp b/cunit/cuReFileSystem.cpp index 4945b1b..d1b6d09 100644 --- a/cunit/cuReFileSystem.cpp +++ b/cunit/cuReFileSystem.cpp @@ -152,8 +152,40 @@ protected: struct stat info; checkEqu(0, stat(path.toUtf8().constData(), &info)); } + void testReOSPermissions(){ + ReOSPermissions p1; + int owner, group; +#if defined __linux__ + owner = getuid(); + group = getgid(); +#else + owner = -1; + group = -1; +#endif + checkEqu(owner, p1.m_user); + checkEqu(group, p1.m_group); + checkEqu( S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH, p1.m_fileMode); + checkEqu(S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP + | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR, p1.m_dirMode); + ReOSPermissions p2(p1); + checkEqu(owner, p2.m_user); + checkEqu(group, p2.m_group); + checkEqu( S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH, p2.m_fileMode); + checkEqu(S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP + | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR, p2.m_dirMode); + p2.m_user = 0x4711; + p2.m_group = 0x1147; + p2.m_dirMode = 123; + p2.m_fileMode = 7766; + p1 = p2; + checkEqu(0x4711, p2.m_user); + checkEqu(0x1147, p2.m_group); + checkEqu(123, p2.m_dirMode); + checkEqu(7766, p2.m_fileMode); + } virtual void run() { + testReOSPermissions(); init(); testReListInfos(); testSetProperties(); diff --git a/cunit/cunit.pro b/cunit/cunit.pro index 8f8bf06..85044ea 100644 --- a/cunit/cunit.pro +++ b/cunit/cunit.pro @@ -16,6 +16,8 @@ TEMPLATE = app INCLUDEPATH = .. SOURCES += main.cpp \ + cuReFileSystem.cpp \ + cuReCryptFileSystem.cpp \ cuReRandomizer.cpp \ cuReQStringUtils.cpp \ cuReStringUtils.cpp \ @@ -42,7 +44,7 @@ SOURCES += main.cpp \ ../gui/ReSettings.cpp \ ../gui/ReEdit.cpp \ ../os/ReFileSystem.cpp \ - cuReFileSystem.cpp \ + ../os/ReCryptFileSystem.cpp \ cuReConfig.cpp \ cuReContainer.cpp \ cuReWriter.cpp \ @@ -51,13 +53,13 @@ SOURCES += main.cpp \ cuReStateStorage.cpp \ cuReSettings.cpp \ cuReMatcher.cpp \ - allTests.cpp \ - ../os/ReCryptFileSystem.cpp + allTests.cpp HEADERS += \ ../base/ReFile.hpp \ ../base/rebase.hpp \ ../gui/ReEdit.hpp \ ../math/ReMatrix.hpp \ - ../math/remath.hpp \ - ../os/ReCryptFileSystem.hpp + ../os/reos.hpp \ + ../math/remath.hpp + diff --git a/os/ReCryptFileSystem.cpp b/os/ReCryptFileSystem.cpp index 1af6608..b24a8eb 100644 --- a/os/ReCryptFileSystem.cpp +++ b/os/ReCryptFileSystem.cpp @@ -149,6 +149,20 @@ ReFileSystem::ErrorCode ReCryptFileSystem::write(const QString& target, return EC_SUCCESS; } +/** + * Adds a file to the current directory. + * + * @param node filename without path + */ +void ReCryptFileSystem::addFile(const QString& node) +{ + QDateTime now = QDateTime::currentDateTime(); + ReFileMetaData entry(node, now, now, m_osPermissions.m_user, + m_osPermissions.m_group, m_osPermissions.m_fileMode, + 0, ++m_maxFileId); + m_list.append(entry); +} + /** * Constructor * @@ -165,7 +179,8 @@ ReCryptDirectory::ReCryptDirectory(ReRandomizer& contentRandom, m_currentNode(), m_fileBuffer(), m_entryBuffer(), - m_blockSize(1024 * 1024) + m_blockSize(1024 * 1024), + m_maxFileId(0) { m_fileBuffer.reserve(m_blockSize); m_entryBuffer.reserve(m_blockSize + MAX_ENTRY_SIZE + 10); @@ -294,6 +309,7 @@ bool ReCryptDirectory::readMetaFile() m_list.clear(); QString fnMetaFile = m_parent->directory() + ReCryptFileSystem::NODE_META_DIR; FILE* fp = fopen(fnMetaFile.toUtf8().constData(), "rb"); + m_maxFileId = 0; if (fp != NULL){ QByteArray header; header.resize(META_DIR_HEADER_LENGTH); @@ -432,6 +448,8 @@ void ReCryptDirectory::splitBlock(bool isLast, QByteArray& block){ file.m_size = src->m_size; file.m_mode = src->m_mode; file.m_id = src->m_id; + if (file.m_id > m_maxFileId) + m_maxFileId = file.m_id; srcPtr += sizeof(FileEntry_t); int nodeLength = src->m_nodeLength != 0 ? src->m_nodeLength : strlen(srcPtr); QByteArray node(srcPtr, nodeLength); @@ -454,3 +472,4 @@ const QString& ReCryptDirectory::hostedFilename(const ReFileMetaData& entry) m_currentNode = ReFileUtils::pathAppend(m_parent->directory(), node); return m_currentNode; } + diff --git a/os/ReCryptFileSystem.hpp b/os/ReCryptFileSystem.hpp index 9d4c139..15181db 100644 --- a/os/ReCryptFileSystem.hpp +++ b/os/ReCryptFileSystem.hpp @@ -60,6 +60,7 @@ protected: QByteArray m_fileBuffer; QByteArray m_entryBuffer; int m_blockSize; + int m_maxFileId; }; /** @@ -104,7 +105,7 @@ public: ReFileSystem& host() const { return m_host; } - + void addFile(const QString& node); protected: ReFileSystem& m_host; }; diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 516ebfd..9edc0b2 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -106,6 +106,16 @@ bool ReFileSystem::writeable() const { return m_writeable; } +ReOSPermissions ReFileSystem::osPermissions() const +{ + return m_osPermissions; +} + +void ReFileSystem::setOsPermissions(const ReOSPermissions& osPermissions) +{ + m_osPermissions = osPermissions; +} + /** * Sets the filesystem to writeable or readonly. * @@ -596,3 +606,45 @@ ReFileMetaData&ReFileMetaData::operator =(const ReFileMetaData& source) { return *this; } +/** + * Constructor. + */ +ReOSPermissions::ReOSPermissions() : + m_user(-1), + m_group(-1), + m_fileMode(0), + m_dirMode(0){ +#if defined __linux__ + m_user = getuid(); + m_group = getgid(); + m_fileMode = S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH; + m_dirMode = S_IWUSR | S_IRUSR | S_IXUSR | S_IWGRP | S_IRGRP + | S_IXGRP | S_IROTH | S_IXOTH | __S_IFDIR; +#endif +} + +/** + * Copy constructor. + * @param source source to copy + */ +ReOSPermissions::ReOSPermissions(const ReOSPermissions& source) : + m_user(source.m_user), + m_group(source.m_group), + m_fileMode(source.m_fileMode), + m_dirMode(source.m_dirMode){ +} + +/** + * Assignment operator. + * + * @param source source to copy + * @return the instance itself + */ +ReOSPermissions&ReOSPermissions::operator =(const ReOSPermissions& source) +{ + m_user = source.m_user; + m_group = source.m_group; + m_fileMode = source.m_fileMode; + m_dirMode = source.m_dirMode; +} + diff --git a/os/ReFileSystem.hpp b/os/ReFileSystem.hpp index f664234..5aad978 100644 --- a/os/ReFileSystem.hpp +++ b/os/ReFileSystem.hpp @@ -12,6 +12,18 @@ #ifndef OS_REFILESYSTEM_HPP_ #define OS_REFILESYSTEM_HPP_ +class ReOSPermissions { +public: + ReOSPermissions(); + ReOSPermissions(const ReOSPermissions& source); + ReOSPermissions& operator =(const ReOSPermissions& source); +public: + int m_user; + int m_group; + mode_t m_fileMode; + mode_t m_dirMode; +}; + class ReFileMetaData { public: ReFileMetaData(); @@ -140,10 +152,13 @@ public: QByteArray fullNameAsUTF8(const QString& node) const { return (m_directory + node).toUtf8(); } - void setWriteable(bool writeable); + ReOSPermissions osPermissions() const; void setBlocksize(int blocksize); + void setOsPermissions(const ReOSPermissions& osPermissions); + void setWriteable(bool writeable); bool writeable() const; + protected: QString m_name; #ifdef __linux__ @@ -157,6 +172,7 @@ protected: QByteArray m_buffer; int m_blocksize; QDateTime m_undefinedTime; + ReOSPermissions m_osPermissions; }; class ReLocalFileSystem: public ReFileSystem { -- 2.39.5