void testReadWrite() {
ReLocalFileSystem fs(m_base, &m_logger);
QByteArray buffer;
+ const char* node1 = "abc.txt";
buffer.append("abcdefghijklmnopqrstuvwxyz");
+ QByteArray full(fs.fullNameAsUTF8(QString(node1)));
- //checkEqu(0, fs.write("abc.txt", 0LL, buffer));
- //checkEqu(0, fs.write("abc.txt", 26LL, buffer));
+ ReFileUtils::writeToFile(full.constData(), buffer.constData());
QByteArray buffer2;
ReFileMetaDataList nodes;
QStringList names;
- names.append("abc.txt");
- names.append("new.txt");
+ names.append(node1);
+ names.append("not_exists.txt");
ReIncludeExcludeMatcher matcher(names, ReQStringUtils::m_emptyList,
Qt::CaseInsensitive, true);
- checkEqu(1, fs.listInfos(matcher, nodes, ReFileSystem::LO_UNDEF));
+ checkEqu(1, fs.listInfos(matcher, nodes, ReFileSystem::LO_FILES));
checkEqu(1, nodes.size());
QByteArray content("This is a content\nLine 2");
- checkEqu(0, fs.createFile("new.txt", false));
+ const char* node2 = "new.txt";
+ ensureNotExist(fs.fullNameAsUTF8(node2));
+ checkEqu(0, fs.createFile(node2, false));
ReFileMetaData meta;
- checkT(fs.exists("new.txt", &meta));
+ checkT(fs.exists(node1, &meta));
ReLeafFile* leaf1 = fs.buildFile(meta);
- leaf1->open(true);
- leaf1->write(content);
- leaf1->close();
+ checkEqu(0, leaf1->open(true));
+ checkEqu(0, leaf1->write(content));
+ checkEqu(0, leaf1->close());
delete leaf1;
- checkT(fs.exists("new.txt", &meta));
+ checkT(fs.exists(node1, &meta));
ReLeafFile* leaf2 = fs.buildFile(meta);
- leaf2->open(false);
- leaf2->read(500, buffer);
- leaf2->close();
- delete leaf2;
+ checkEqu(0, leaf2->open(false));
+ checkEqu(0, leaf2->read(500, buffer));
+ checkEqu(0, leaf2->close());
+ checkEqu(content.constData(), buffer);
- //checkEqu(0, fs.read(nodes.at(0), 0LL, 3, buffer2));
- checkEqu("abc", buffer2);
- //checkEqu(0, fs.read(nodes.at(0), 3LL, 7, buffer2));
- checkEqu("defghij", buffer2);
- //checkEqu(0, fs.read(nodes.at(0), 10LL, 99, buffer2));
- checkEqu("klmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", buffer2);
+ checkEqu(0, leaf2->open(false));
+ checkEqu(0, leaf2->read(3, buffer));
+ checkEqu(content.mid(0, 3).constData(), buffer);
+ checkEqu(0, leaf2->read(8, buffer));
+ checkEqu(content.mid(3, 8).constData(), buffer);
+ checkEqu(0, leaf2->close());
+ delete leaf2;
}
void testSetProperties() {
ReLocalFileSystem fs(m_base, &m_logger);
ReFileMetaData meta1;
- const char* trgNode = "later.txt";
- ReFileUtils::tempFile(trgNode, "refilesystem", true);
+ const char* node1 = "later.txt";
+ const char* node2 = "properties.txt";
+ QByteArray full(fs.fullNameAsUTF8(node1));
+ ensureNotExist(full);
+ full = fs.fullNameAsUTF8(node2);
+ ReFileUtils::writeToFile(full, node2);
+ ReFileUtils::tempFile(node1, "refilesystem", true);
QDateTime modified = QDateTime::fromString("2015.09.12 11:44:55.765",
"yyyy.MM.dd hh:mm:ss.zzz");
- ReFileMetaData meta2(trgNode, modified, ReFileUtils::m_undefinedTime,
+ ReFileMetaData meta2(node1, modified, ReFileUtils::m_undefinedTime,
-1, -1, (mode_t) - 1, 1);
- checkT(fs.first("test1.txt", meta1));
+ checkT(fs.first(node2, meta1, ReFileSystem::LO_FILES));
checkEqu(0, fs.setProperties(meta2, meta1, true));
ReFileMetaData meta3;
- checkT(fs.first(trgNode, meta3));
+ checkT(fs.first(node1, meta3));
checkEqu(meta3.m_modified, modified);
}
void testSetPropertiesOwner() {
ReFileUtils::deleteTree(base2, false, &m_logger);
ReLocalFileSystem fsTarget(base2, &m_logger);
ReFileMetaData metaSource;
- checkT(fsSource.first("test3.txt", metaSource));
+ const char* node = "test3.txt";
+ checkT(fsSource.first(node, metaSource));
+
+ QByteArray full(fsTarget.fullNameAsUTF8(node));
+ ensureNotExist(full.constData());
+
checkEqu(0, fsTarget.copy(metaSource, fsSource));
+
ReFileMetaData metaTarget;
- checkT(fsTarget.first("test3.txt", metaTarget));
+ checkT(fsTarget.first(node, metaTarget));
compareMeta(metaSource, metaTarget);
checkEqu(0, fsTarget.makeDir("dir.01"));
checkEqu(0, fsTarget.setDirectory("dir.01"));
*
* @param pattern pattern to find
* @param file OUT: the found file (valid only if return code is <code>true</code>
+ * @param options defines type of the found file, e.g. LO_FILE
* @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,
+ ListOptions options) {
ReFileMetaDataList list;
QStringList names;
names.append(pattern);
ReIncludeExcludeMatcher matcher(names, ReQStringUtils::m_emptyList,
Qt::CaseInsensitive, true);
- listInfos(matcher, list);
+ listInfos(matcher, list, options);
bool rc = list.size() > 0;
if (rc)
file = list.at(0);
*/
bool ReLocalFileSystem::exists(const QString& node, ReFileMetaData* metaData) const
{
- QByteArray full;
- full.resize(m_directory.length() + 10 + node.length());
- full = m_directory.toUtf8();
- full.append(node.toUtf8());
+ QByteArray full(fullNameAsUTF8(node));
struct stat info;
- bool rc = stat(full.constData(), &info) != 0;
+ bool rc = stat(full.constData(), &info) == 0;
if (rc && metaData != NULL){
metaData->m_node = node;
metaData->m_modified = QDateTime::fromTime_t(info.st_mtime);
? m_dir.entryList() : m_dir.entryList(patterns);
QStringList::const_iterator it;
QByteArray full = m_directory.toUtf8();
- full.append(OS_SEPARATOR);
int pathLength = full.length();
struct stat info;
const ReListMatcher& excludeMatcher = matcher.excludes();
if (ReFileUtils::isAbsolutPath(path)){
m_dir.setPath(path);
rc = m_dir.exists() ? EC_SUCCESS : EC_PATH_NOT_FOUND;
- } else
- rc = m_dir.setCurrent(ReFileUtils::pathAppend(
- m_dir.absolutePath(), path))
- ? EC_SUCCESS : EC_PATH_NOT_FOUND;
+ } else {
+ QString dir = ReFileUtils::pathAppend(m_directory, path);
+ m_dir.setPath(dir);
+ rc = m_dir.exists() ? EC_SUCCESS : EC_PATH_NOT_FOUND;
+ }
if (rc == EC_SUCCESS){
- m_directory = m_dir.absolutePath();
+ m_directory = m_dir.path();
ReQStringUtils::ensureLastChar(m_directory, OS_SEPARATOR);
}
return rc;