From bc00dda9774caa5caffda02f58b8f109f9b8ea0a Mon Sep 17 00:00:00 2001 From: hama Date: Thu, 5 Nov 2015 23:53:10 +0100 Subject: [PATCH] dayly work --- base/ReFileUtils.cpp | 8 +++--- cunit/cuReFileUtils.cpp | 10 ++++---- guiwidget/ReFileTable.cpp | 13 +++++----- os/ReFileSystem.cpp | 54 ++++++++++++++++++++++++++++++++++++++- os/ReFileSystem.hpp | 16 ++++++++++++ 5 files changed, 85 insertions(+), 16 deletions(-) diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index 3e9aa57..58a6f30 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -481,9 +481,9 @@ void ReFileUtils::splitUrl(const QString& url, QString* protocol, QString* host, if (url.length() >= start + 2 && url.at(start) == '/' && url.at(start + 1) == '/'){ ix = url.indexOf("/", start + 2); if (ix < 0) - ix = 2; + ix = start + 2; if (host != NULL) - *host = url.mid(start, ix); + *host = url.mid(start, ix - start); start = ix; } ix = url.lastIndexOf(OS_SEPARATOR); @@ -492,7 +492,7 @@ void ReFileUtils::splitUrl(const QString& url, QString* protocol, QString* host, if (ix >= 0){ ix++; if (path != NULL) - *path = url.mid(start, ix); + *path = url.mid(start, ix - start); start = ix; } ix = url.indexOf('?', start); @@ -501,7 +501,7 @@ void ReFileUtils::splitUrl(const QString& url, QString* protocol, QString* host, *node = url.mid(start); } else { if (node != NULL) - *node = url.mid(start, ix); + *node = url.mid(start, ix - start); if (params != NULL) *params = url.mid(ix); } diff --git a/cunit/cuReFileUtils.cpp b/cunit/cuReFileUtils.cpp index e321841..9f12e2e 100644 --- a/cunit/cuReFileUtils.cpp +++ b/cunit/cuReFileUtils.cpp @@ -296,7 +296,7 @@ public: checkReplaceExt("/abc.1/def.123", "/abc.1/def.xyz", ".123", __LINE__); checkReplaceExt("/abc.1/def.123", "/abc.1/def", ".123", __LINE__); } - void checkUrl(const char* url, const char* expProto, char* expHost, + void checkUrl(const char* url, const char* expProto, const char* expHost, const char* expPath, const char* expNode, const char* expParams){ QString protocol, host, path, node, params; ReFileUtils::splitUrl(QString(url), &protocol, &host, &path, &node, ¶ms); @@ -307,10 +307,10 @@ public: checkEqu(expParams, params); } void testSplitUrl(){ - checkUrl("file:///abc/def.x", "file:", "//", "/abc", "def.x", ""); - checkUrl("file:/abc/def.x", "file:", "", "/abc", "def.x", ""); - checkUrl("///abc/def.x", "", "//", "/abc", "def.x", ""); - checkUrl("/abc/def.x", "", "", "/abc", "def.x", ""); + checkUrl("file:///abc/def.x", "file:", "//", "/abc/", "def.x", ""); + checkUrl("file:/abc/def.x", "file:", "", "/abc/", "def.x", ""); + checkUrl("///abc/def.x", "", "//", "/abc/", "def.x", ""); + checkUrl("/abc/def.x", "", "", "/abc/", "def.x", ""); checkUrl("/def.x", "", "", "/", "def.x", ""); checkUrl("def.x", "", "", "", "def.x", ""); diff --git a/guiwidget/ReFileTable.cpp b/guiwidget/ReFileTable.cpp index 1d699a0..36d72b8 100644 --- a/guiwidget/ReFileTable.cpp +++ b/guiwidget/ReFileTable.cpp @@ -169,19 +169,20 @@ void ReFileTable::copyFromClipboard(int currentRow){ if (! mimeData->hasUrls()) say(LOG_INFO, tr("No files in clipboard")); else { - QList urls = mimeData->urls(); - QList::const_iterator it; - QString path, node; + QList urls = mimeData->urls(); + QList::const_iterator it; + ReFileMetaData srcFile; + QString url; for (it = urls.cbegin(); it != urls.cend(); ++it){ - QString url = it->url(); + url = it->url(); if (source == NULL){ if ( (source = ReFileSystem::buildFromUrl(url)) == NULL){ say(LOG_ERROR, tr("unknown filesystem: %1").arg(url)); break; } } - ReFileUtils::splitUrl2(NULL, &path, &node); - fileSystem->copy() + if (source->findByUrl(url, srcFile)) + fileSystem->copy(srcFile, *source); } } diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 5a58b7f..e482d5e 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -183,6 +183,26 @@ QString ReFileSystem::errorMessage(ReFileSystem::ErrorCode errorCode) return rc; } +/** + * Returns the meta info of a file given by its url. + * + * Note: protocol and server of the URL will be ignored. + * + * @param url filename as URL + * @param metaData OUT: the metadata of the found file if found + * @return true: the file has been found
+ * false: the file was not found + */ +bool ReFileSystem::findByUrl(const QString& url, ReFileMetaData& metaData) { + bool found = false; + QString path, node; + ReFileUtils::splitUrl(url, NULL, NULL, &path, &node); + if (setDirectory(path) == EC_SUCCESS){ + found = first(node, metaData); + } + return found; +} + /** * Finds the first file given by a pattern. * @@ -236,11 +256,29 @@ int ReFileSystem::nodesByPrefix(QString& prefix, ListOptions options, return rc; } +/** + * Returns the operating system permission data of the filesystem. + * + * @return the permission data: owner, group... + */ ReOSPermissions ReFileSystem::osPermissions() const { return m_osPermissions; } +/** + * Tests whether a second filesystem has the same current directory. + * + * @param fileSystem the other filesystem + * @return true: both filesystems uses the identical + * current directory: same filesytem type, same path + */ +bool ReFileSystem::sameCurrentDirectory(ReFileSystem& fileSystem) const +{ + bool rc = fileSystem.m_name == m_name && fileSystem.directory() == m_directory; + return rc; +} + void ReFileSystem::setOsPermissions(const ReOSPermissions& osPermissions) { m_osPermissions = osPermissions; @@ -405,7 +443,7 @@ ReFileSystem::ErrorCode ReLocalFileSystem::makeDir(const QString& node) { * Changes the current directory of the filesystem. * * @param path the new current directory - * @return 0: success
+ * @return EC_SUCCESS: success
* EC_PATH_NOT_FOUND directory does not exist
* EC_NOT_ACCESSIBLE parent not readable */ @@ -425,6 +463,20 @@ ReFileSystem::ErrorCode ReLocalFileSystem::setDirectory(const QString& path) { return rc; } +/** + * Returns the canonical form of a given path. + * + * @param path path to convert + * @return all nodes of the parts which are links are replaced by its + * link targets + */ +QString ReLocalFileSystem::canonicalPathOf(const QString& path) +{ + QString rc = ReFileUtils::cleanPath(path); + assert(false); + return rc; +} + /** * Reads a part of a file into a buffer. * diff --git a/os/ReFileSystem.hpp b/os/ReFileSystem.hpp index 946373e..2608281 100644 --- a/os/ReFileSystem.hpp +++ b/os/ReFileSystem.hpp @@ -76,6 +76,12 @@ public: ReFileSystem(const QString& name, ReLogger* logger); virtual ~ReFileSystem(); public: + /** Returns the canonical form of a given path. + * @param path path to convert + * @return all nodes of the parts which are links are replaced by its + * link targets + */ + virtual QString canonicalPathOf(const QString& path) = 0; /** Frees resources like open files. */ virtual void close() = 0; @@ -139,6 +145,7 @@ public: virtual QString errorMessage(ErrorCode rc); public: int blocksize() const; + bool findByUrl(const QString& url, ReFileMetaData& metaData); bool first(const QString& pattern, ReFileMetaData& file); /** Returns the full name (with path). * @param node the name without path @@ -156,6 +163,7 @@ public: } int nodesByPrefix(QString& prefix, ListOptions options, QStringList& list); ReOSPermissions osPermissions() const; + bool sameCurrentDirectory(ReFileSystem& fileSystem) const; void setBlocksize(int blocksize); void setOsPermissions(const ReOSPermissions& osPermissions); void setWriteable(bool writeable); @@ -170,6 +178,8 @@ protected: #endif // ending with OS_SEPARATOR: QString m_directory; + // All links are replaced by its targets: + QString m_canonicalDirectory; bool m_writeable; ReLogger* m_logger; QByteArray m_buffer; @@ -187,6 +197,12 @@ public: ErrorCode setDirectory(const QString& path); public: + /** Returns the canonical form of a given path. + * @param path path to convert + * @return all nodes of the parts which are links are replaced by its + * link targets + */ + virtual QString canonicalPathOf(const QString& path); // ReFileSystem interface virtual void close(); virtual int listInfos(const ReIncludeExcludeMatcher& matcher, -- 2.39.5