summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdebug.cpp2
-rw-r--r--src/corelib/io/qdir.cpp5
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp4
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp17
-rw-r--r--src/corelib/io/qurl.cpp42
-rw-r--r--src/corelib/io/qurlidna.cpp2
6 files changed, 53 insertions, 19 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 05920f4575..3370cce6d5 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -383,7 +383,7 @@ QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
}
/*!
- Destroyes a QDebugStateSaver instance, which restores the settings
+ Destroys a QDebugStateSaver instance, which restores the settings
used when the QDebugStateSaver instance was created.
\sa QDebug::setAutoInsertSpaces(), QDebug::autoInsertSpaces()
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 909143ecf3..ec7d89fa87 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -1944,8 +1944,9 @@ QString QDir::homePath()
On Unix/Linux systems this is the path in the \c TMPDIR environment
variable or \c{/tmp} if \c TMPDIR is not defined. On Windows this is
usually the path in the \c TEMP or \c TMP environment
- variable. Whether a directory separator is added to the end or
- not, depends on the operating system.
+ variable.
+ The path returned by this method doesn't end with a directory separator
+ unless it is the root directory (of a drive).
\sa temp(), currentPath(), homePath(), rootPath()
*/
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index e6b4e5f754..2327c11c69 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -721,13 +721,13 @@ QString QFileSystemEngine::tempPath()
if (temp.isEmpty()) {
qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /tmp.");
- temp = QLatin1String("/tmp/");
+ temp = QLatin1String("/tmp");
}
return QDir::cleanPath(temp);
#else
QString temp = QFile::decodeName(qgetenv("TMPDIR"));
if (temp.isEmpty())
- temp = QLatin1String("/tmp/");
+ temp = QLatin1String("/tmp");
return QDir::cleanPath(temp);
#endif
}
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 1b9078f712..e2ed7c3766 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -205,6 +205,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// value can start with $HOME
if (value.startsWith(QLatin1String("$HOME")))
value = QDir::homePath() + value.mid(5);
+ if (value.length() > 1 && value.endsWith(QLatin1Char('/')))
+ value.chop(1);
return value;
}
}
@@ -257,10 +259,17 @@ static QStringList xdgDataDirs()
dirs.append(QString::fromLatin1("/usr/local/share"));
dirs.append(QString::fromLatin1("/usr/share"));
} else {
- dirs = xdgDataDirsEnv.split(QLatin1Char(':'));
- // Normalize paths
- for (int i = 0; i < dirs.count(); i++)
- dirs[i] = QDir::cleanPath(dirs.at(i));
+ dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+ // Normalize paths, skip relative paths
+ QMutableListIterator<QString> it(dirs);
+ while (it.hasNext()) {
+ const QString dir = it.next();
+ if (!dir.startsWith(QLatin1Char('/')))
+ it.remove();
+ else
+ it.setValue(QDir::cleanPath(dir));
+ }
// Remove duplicates from the list, there's no use for duplicated
// paths in XDG_DATA_DIRS - if it's not found in the given
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index eac5a0b738..f17215964f 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -414,10 +414,16 @@ static inline QString fileScheme()
return QStringLiteral("file");
}
+#ifdef Q_COMPILER_CLASS_ENUM
+# define colon_uchar : uchar
+#else
+# define colon_uchar
+#endif
+
class QUrlPrivate
{
public:
- enum Section {
+ enum Section colon_uchar {
Scheme = 0x01,
UserName = 0x02,
Password = 0x04,
@@ -432,6 +438,10 @@ public:
FullUrl = 0xff
};
+ enum Flags colon_uchar {
+ IsLocalFile = 0x01
+ };
+
enum ErrorCode {
// the high byte of the error code matches the Section
// the first item in each value must be the generic "Invalid xxx Error"
@@ -519,6 +529,8 @@ public:
inline bool hasQuery() const { return sectionIsPresent & Query; }
inline bool hasFragment() const { return sectionIsPresent & Fragment; }
+ inline bool isLocalFile() const { return flags & IsLocalFile; }
+
QString mergePaths(const QString &relativePath) const;
QAtomicInt ref;
@@ -539,12 +551,18 @@ public:
// - Path (there's no path delimiter, so we optimize its use out of existence)
// Schemes are never supposed to be empty, but we keep the flag anyway
uchar sectionIsPresent;
+ uchar flags;
+
+ // 32-bit: 2 bytes tail padding available
+ // 64-bit: 6 bytes tail padding available
};
+#undef colon_uchar
inline QUrlPrivate::QUrlPrivate()
: ref(1), port(-1),
error(0),
- sectionIsPresent(0)
+ sectionIsPresent(0),
+ flags(0)
{
}
@@ -558,7 +576,8 @@ inline QUrlPrivate::QUrlPrivate(const QUrlPrivate &copy)
query(copy.query),
fragment(copy.fragment),
error(copy.cloneError()),
- sectionIsPresent(copy.sectionIsPresent)
+ sectionIsPresent(copy.sectionIsPresent),
+ flags(copy.flags)
{
}
@@ -956,6 +975,12 @@ inline bool QUrlPrivate::setScheme(const QString &value, int len, bool doSetErro
schemeData[i] = c + 0x20;
}
}
+
+ // did we set to the file protocol?
+ if (scheme == fileScheme())
+ flags |= IsLocalFile;
+ else
+ flags &= ~IsLocalFile;
return true;
}
@@ -1312,6 +1337,7 @@ inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode
// / other path types here
sectionIsPresent = 0;
+ flags = 0;
clearError();
// find the important delimiters
@@ -1867,6 +1893,7 @@ void QUrl::setScheme(const QString &scheme)
if (scheme.isEmpty()) {
// schemes are not allowed to be empty
d->sectionIsPresent &= ~QUrlPrivate::Scheme;
+ d->flags &= ~QUrlPrivate::IsLocalFile;
d->scheme.clear();
} else {
d->setScheme(scheme, scheme.length(), /* do set error */ true);
@@ -3104,6 +3131,7 @@ QUrl QUrl::resolved(const QUrl &relative) const
t.d->sectionIsPresent |= QUrlPrivate::Scheme;
else
t.d->sectionIsPresent &= ~QUrlPrivate::Scheme;
+ t.d->flags |= d->flags & QUrlPrivate::IsLocalFile;
}
t.d->fragment = relative.d->fragment;
if (relative.d->hasFragment())
@@ -3177,7 +3205,6 @@ QString QUrl::toString(FormattingOptions options) const
// - there's no query or fragment to return
// that is, either they aren't present, or we're removing them
// - it's a local file
- // (test done last since it's the most expensive)
if (options.testFlag(QUrl::PreferLocalFile) && !options.testFlag(QUrl::RemovePath)
&& (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
&& (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
@@ -3201,6 +3228,7 @@ QString QUrl::toString(FormattingOptions options) const
url += QLatin1String("//");
d->appendAuthority(url, options, QUrlPrivate::FullUrl);
} else if (isLocalFile() && pathIsAbsolute) {
+ // Comply with the XDG file URI spec, which requires triple slashes.
url += QLatin1String("//");
}
@@ -3755,11 +3783,7 @@ QString QUrl::toLocalFile() const
*/
bool QUrl::isLocalFile() const
{
- if (!d) return false;
-
- if (d->scheme != fileScheme())
- return false; // not file
- return true;
+ return d && d->isLocalFile();
}
/*!
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp
index bf2c07e0e0..4e9b257c7b 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -2603,7 +2603,7 @@ QStringList QUrl::idnWhitelist()
Note that if you call this function, you need to do so \e before
you start any threads that might access idnWhitelist().
- Qt has comes a default list that contains the Internet top-level domains
+ Qt comes with a default list that contains the Internet top-level domains
that have published support for Internationalized Domain Names (IDNs)
and rules to guarantee that no deception can happen between similarly-looking
characters (such as the Latin lowercase letter \c 'a' and the Cyrillic