]> gitweb.hamatoma.de Git - reqt/commitdiff
dayly work
authorhama <hama@siduction.net>
Thu, 5 Nov 2015 22:53:10 +0000 (23:53 +0100)
committerhama <hama@siduction.net>
Thu, 5 Nov 2015 22:53:10 +0000 (23:53 +0100)
base/ReFileUtils.cpp
cunit/cuReFileUtils.cpp
guiwidget/ReFileTable.cpp
os/ReFileSystem.cpp
os/ReFileSystem.hpp

index 3e9aa57be067ca41d58c65e027e5b5ef505ebcf2..58a6f30c57e17aaa1966ddbcad50a8c632a98591 100644 (file)
@@ -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);
        }
index e321841f38d3218393d33cada44986a4662e259f..9f12e2efb5763f2e1b897592a7d18fe87816934f 100644 (file)
@@ -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, &params);
@@ -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", "");
 
index 1d699a0ff7fbd3c51d1666370beeefbd6d41962b..36d72b8abbf7613eeeada01e0ebb9aae8947e727 100644 (file)
@@ -169,19 +169,20 @@ void ReFileTable::copyFromClipboard(int currentRow){
        if (! mimeData->hasUrls())
                say(LOG_INFO, tr("No files in clipboard"));
        else {
-               QList<Url> urls = mimeData->urls();
-               QList<Url>::const_iterator it;
-               QString path, node;
+               QList<QUrl> urls = mimeData->urls();
+               QList<QUrl>::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);
 
                }
        }
index 5a58b7f382713977f8357acb0205b50d9babda31..e482d5e830acfb024415b0d3e196048d7767e700 100644 (file)
@@ -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                     <code>true</code>: the file has been found<br>
+ *                                     <code>false</code>: 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                             <code>true</code>: 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<br>
+ * @return             EC_SUCCESS: success<br>
  *                             EC_PATH_NOT_FOUND       directory does not exist<br>
  *                             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.
  *
index 946373e64b885773d75af532324cd09e9c16786a..26082813576860966d9f57b03c4d9ca41865cb20 100644 (file)
@@ -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,