<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
- <cconfiguration id="0.800691153">
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.800691153" moduleId="org.eclipse.cdt.core.settings" name="Default">
+ <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1502790854">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1502790854" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
- <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration buildProperties="" description="" id="0.800691153" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
- <folderInfo id="0.800691153." name="/" resourcePath="">
- <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.295364492" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
- <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.295364492.978176953" name=""/>
- <builder id="org.eclipse.cdt.build.core.settings.default.builder.1827277458" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
- <tool id="org.eclipse.cdt.build.core.settings.holder.libs.247202732" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
- <tool id="org.eclipse.cdt.build.core.settings.holder.1313807664" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1190613361" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
- </tool>
- <tool id="org.eclipse.cdt.build.core.settings.holder.814499006" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1978993617" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
- </tool>
- <tool id="org.eclipse.cdt.build.core.settings.holder.1957234262" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.151373444" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
- </tool>
+ <configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.1502790854" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+ <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1502790854.1490597040" name="/" resourcePath="">
+ <toolChain id="cdt.managedbuild.toolchain.gnu.base.1847887429" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
+ <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.766304052" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
+ <builder id="cdt.managedbuild.target.gnu.builder.base.1548452526" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.archiver.base.1423237140" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.637115277" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1722302407" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1123712484" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1202319664" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.assembler.base.1781648326" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
</toolChain>
</folderInfo>
- <sourceEntries>
- <entry excluding="rqfilesearch|appl" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
- <entry excluding="rqfilesearch" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="appl"/>
- </sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
- <storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <project id="rplqt.null.1220808761" name="rplqt"/>
- </storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.800691153">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <project id="reqt.null.1795700801" name="reqt"/>
+ </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
- <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>
QStringList* ReListMatcher::m_allMatchingList = NULL;
ReListMatcher* ReListMatcher::m_allMatcher = NULL;
-
+ReIncludeExcludeMatcher* ReIncludeExcludeMatcher::m_allMatcher = NULL;
/**
* Constructor.
*
*/
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);
}
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)) {
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;
* 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);
}
/**
* @param caseSensivitiy <code>true</code>: the character case is relevant
*/
void ReListMatcher::setCaseSensivitiy(
- const Qt::CaseSensitivity& caseSensivitiy) {
+ const Qt::CaseSensitivity& caseSensivitiy) {
QList<ReMatcher*>::const_iterator 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;
* 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;
}
/**
* @param caseSensivitiy <code>true</code>: the character case is relevant
*/
void ReIncludeExcludeMatcher::setCaseSensivitiy(
- const Qt::CaseSensitivity& caseSensivitiy) {
+ const Qt::CaseSensitivity& caseSensivitiy) {
m_includes.setCaseSensivitiy(caseSensivitiy);
m_excludes.setCaseSensivitiy(caseSensivitiy);
}
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;
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;
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();
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;
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<br>
+ *
+ * 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:
+ * <code>assert(indexOf[charset[ix] - minChar] == ix
+ * && charSet[indexOf[cc - minChar] == cc)</code>
+ *
+ * @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 <code>indexOf</code>
+ * @return <code>true</code>: success<br>
+ * <code>false</code>: 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;
+}
#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);
}
static void testOs() {
void testReFileSystem();
+ void testReCryptFileSystem();
+ testReCryptFileSystem();
testReFileSystem();
}
void allTests() {
--- /dev/null
+/*
+ * 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;
+}
+
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();
INCLUDEPATH = ..
SOURCES += main.cpp \
+ cuReFileSystem.cpp \
+ cuReCryptFileSystem.cpp \
cuReRandomizer.cpp \
cuReQStringUtils.cpp \
cuReStringUtils.cpp \
../gui/ReSettings.cpp \
../gui/ReEdit.cpp \
../os/ReFileSystem.cpp \
- cuReFileSystem.cpp \
+ ../os/ReCryptFileSystem.cpp \
cuReConfig.cpp \
cuReContainer.cpp \
cuReWriter.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
+
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
*
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);
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);
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);
m_currentNode = ReFileUtils::pathAppend(m_parent->directory(), node);
return m_currentNode;
}
+
QByteArray m_fileBuffer;
QByteArray m_entryBuffer;
int m_blockSize;
+ int m_maxFileId;
};
/**
ReFileSystem& host() const {
return m_host;
}
-
+ void addFile(const QString& node);
protected:
ReFileSystem& m_host;
};
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.
*
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;
+}
+
#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();
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__
QByteArray m_buffer;
int m_blocksize;
QDateTime m_undefinedTime;
+ ReOSPermissions m_osPermissions;
};
class ReLocalFileSystem: public ReFileSystem {