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);
if (ix >= 0){
ix++;
if (path != NULL)
- *path = url.mid(start, ix);
+ *path = url.mid(start, ix - start);
start = ix;
}
ix = url.indexOf('?', start);
*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);
}
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);
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", "");
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);
}
}
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.
*
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;
* 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
*/
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.
*
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;
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
}
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);
#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;
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,