checkEqu(123, p2.m_dirMode);
checkEqu(7766, p2.m_fileMode);
}
+ void checkMove(const char* node1, const char* node2){
+ ReLocalFileSystem fsSource(m_base, &m_logger);
+ QByteArray base2 = ReFileUtils::tempDir("refilesystem.trg", NULL,
+ false);
+ ReFileUtils::deleteTree(base2, false, &m_logger);
+ ReLocalFileSystem fsTarget(base2, &m_logger);
+ ReFileMetaData metaSource;
+ const char* content = "content move1.txt";
+ QByteArray fullSrc(fsSource.fullNameAsUTF8(node1));
+ ReFileUtils::writeToFile(fullSrc, content);
+ checkT(fsSource.first(node1, metaSource));
+
+ QByteArray fullTrg(fsTarget.fullNameAsUTF8(node2 == NULL ? node1 : node2));
+ ensureNotExist(fullTrg.constData());
+
+ checkT(fsSource.exists(node1, &metaSource));
+ if (node2 == NULL)
+ checkEqu(0, fsTarget.move(metaSource, fsSource));
+ else
+ checkEqu(0, fsTarget.move(metaSource, fsSource, node2));
+
+ checkF(exists(fullSrc));
+ checkT(exists(fullTrg));
+ checkF(fsSource.exists(node1));
+ checkT(fsTarget.exists(node2 == NULL ? node1 : node2));
+ QByteArray buffer;
+ checkEqu(content, ReFileUtils::readFromFile(fullTrg, buffer));
+ }
+
+ void testMove(){
+ checkMove("move1.txt", "move2.txt");
+ checkMove("move1.txt", NULL);
+ }
virtual void run() {
testReOSPermissions();
testSetPropertiesOwner();
testCopy();
testReadWrite();
+ testMove();
}
};
void testReFileSystem() {
*
*/
ReFileSystem::ErrorCode ReFileSystem::copy(ReFileMetaData& source,
- ReFileSystem& sourceFS) {
+ ReFileSystem& sourceFS, QString targetNode) {
int blocksize = min(m_blocksize, sourceFS.blocksize());
ErrorCode rc = EC_SUCCESS;
ErrorCode rc2;
int64_t size = 0;
+ if (targetNode.isEmpty())
+ targetNode = source.m_node;
ReLeafFile* sourceFile = sourceFS.buildFile(source);
ReFileMetaData targetMeta;
- if (! exists(source.m_node, &targetMeta)){
- rc = createFile(source.m_node, false, &targetMeta);
+ if (! exists(targetNode, &targetMeta)){
+ rc = createFile(targetNode, false, &targetMeta);
}
if (rc == EC_SUCCESS){
ReLeafFile* targetFile = buildFile(targetMeta);
}
sourceFile->close();
targetFile->close();
- ReFileMetaData target(source.m_node, ReFileUtils::m_undefinedTime,
+ ReFileMetaData target(targetNode, ReFileUtils::m_undefinedTime,
ReFileUtils::m_undefinedTime, m_uid, m_gid);
+ QString node = source.m_node;
+ source.m_node = targetNode;
setProperties(source, target, false);
+ source.m_node = node;
delete sourceFile;
delete targetFile;
}
return rc;
}
+/**
+ * Move a file from a source filesystem to the current directory of the instance.
+ *
+ * @param source meta data of the source file (in current directory)
+ * @param sourceFS the filesystem containing the source
+ * @return EC_SUCCESS: success<br>
+ *
+ */
+ReFileSystem::ErrorCode ReFileSystem::move(ReFileMetaData& source,
+ ReFileSystem& sourceFS, QString targetNode) {
+ if (targetNode.isEmpty())
+ targetNode = source.m_node;
+ ErrorCode rc = copy(source, sourceFS, targetNode);
+ if (rc == EC_SUCCESS){
+ rc = sourceFS.remove(source);
+ }
+ return rc;
+}
+
/**
* Finds all nodes with a given prefix.
*
ReFileSystem::ErrorCode ReLocalFileSystem::remove(const ReFileMetaData& node) {
ErrorCode rc = EC_SUCCESS;
if (!m_writeable) {
- m_logger->log(LOG_ERROR, LOC_REMOVE_1, "filesystem is readonly");
+ m_logger->log(LOG_ERROR, LOC_REMOVE_1, "remove(): 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",
+ m_logger->logv(LOG_ERROR, LOC_REMOVE_2, "remove(): node does not exists: %s",
fullNameAsUTF8(node.m_node).constData());
rc = EC_NOT_EXISTS;
} else {
ReFileMetaData meta;
return exists(node, &meta) ? buildFile(meta) : NULL;
}
-
- virtual ErrorCode copy(ReFileMetaData& source, ReFileSystem& sourceFS);
virtual QString errorMessage(ErrorCode rc);
+ virtual ErrorCode copy(ReFileMetaData& source, ReFileSystem& sourceFS,
+ QString targetNode = ReQStringUtils::m_empty);
+ virtual ErrorCode move(ReFileMetaData& source, ReFileSystem& sourceFS,
+ QString targetNode = ReQStringUtils::m_empty);
public:
int blocksize() const;
bool findByUrl(const QString& url, ReFileMetaData& metaData);