summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-04-11 10:48:44 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-04-11 10:48:44 (GMT)
commit1062da14facb7dd10f0928a4c242549d3626f9ba (patch)
tree4462fcaa82b45c47eddcdcb1d89e1cc03de45a85 /src/corelib/io
parent847df81a5680fe4d71196d0afe5e68e41ae49700 (diff)
parentdd60cf7ba8afdf5c84f5793c1e1d08ab18303a74 (diff)
downloadQt-1062da14facb7dd10f0928a4c242549d3626f9ba.zip
Qt-1062da14facb7dd10f0928a4c242549d3626f9ba.tar.gz
Qt-1062da14facb7dd10f0928a4c242549d3626f9ba.tar.bz2
Merge branch 'master' of scm.dev.troll.no:qt/qt-earth-team into symbian-socket-engine
Conflicts: src/s60installs/bwins/QtCoreu.def src/s60installs/bwins/QtGuiu.def src/s60installs/bwins/QtNetworku.def src/s60installs/eabi/QtCoreu.def src/s60installs/eabi/QtGuiu.def src/s60installs/eabi/QtNetworku.def src/s60installs/eabi/QtOpenVGu.def tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdir.cpp15
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp1
-rw-r--r--src/corelib/io/qfilesystemwatcher_symbian.cpp5
-rw-r--r--src/corelib/io/qiodevice.cpp9
-rw-r--r--src/corelib/io/qprocess.cpp48
-rw-r--r--src/corelib/io/qprocess.h4
-rw-r--r--src/corelib/io/qprocess_p.h2
-rw-r--r--src/corelib/io/qprocess_symbian.cpp15
-rw-r--r--src/corelib/io/qprocess_unix.cpp4
-rw-r--r--src/corelib/io/qresource.cpp6
-rw-r--r--src/corelib/io/qtemporaryfile.cpp275
11 files changed, 183 insertions, 201 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 42f1652..166513a 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -196,12 +196,19 @@ inline void QDirPrivate::resolveAbsoluteEntry() const
if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty())
return;
- if (dirEntry.isRelative()) {
- QFileSystemEntry answer = QFileSystemEngine::absoluteName(dirEntry);
- absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(answer.filePath()), QFileSystemEntry::FromInternalPath());
+ QString absoluteName;
+ if (fileEngine.isNull()) {
+ if (!dirEntry.isRelative()) {
+ absoluteDirEntry = dirEntry;
+ return;
+ }
+
+ absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
} else {
- absoluteDirEntry = dirEntry;
+ absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
}
+
+ absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName), QFileSystemEntry::FromInternalPath());
}
/* For sorting */
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 1becea5..c9ebaa4 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -176,6 +176,7 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
#if !defined(Q_OS_MAC) && _POSIX_VERSION < 200809L
// realpath(X,0) is not supported
+ Q_UNUSED(data);
return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath()));
#else
char *ret = 0;
diff --git a/src/corelib/io/qfilesystemwatcher_symbian.cpp b/src/corelib/io/qfilesystemwatcher_symbian.cpp
index 29ec77a..8e8dfe5 100644
--- a/src/corelib/io/qfilesystemwatcher_symbian.cpp
+++ b/src/corelib/io/qfilesystemwatcher_symbian.cpp
@@ -95,7 +95,10 @@ void QNotifyChangeEvent::RunL()
SetActive();
if (!failureCount) {
- QT_TRYCATCH_LEAVING(engine->emitPathChanged(this));
+ int err;
+ QT_TRYCATCH_ERROR(err, engine->emitPathChanged(this));
+ if (err != KErrNone)
+ qWarning("QNotifyChangeEvent::RunL() - emitPathChanged threw exception (Converted error code: %d)", err);
}
}
}
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 76e8409..8759f8b 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -1628,10 +1628,11 @@ QString QIODevice::errorString() const
\fn qint64 QIODevice::readData(char *data, qint64 maxSize)
Reads up to \a maxSize bytes from the device into \a data, and
- returns the number of bytes read or -1 if an error occurred. If
- there are no bytes to be read, this function should return -1 if
- there can never be more bytes available (for example: socket
- closed, pipe closed, sub-process finished).
+ returns the number of bytes read or -1 if an error occurred.
+
+ If there are no bytes to be read and there can never be more bytes
+ available (examples include socket closed, pipe closed, sub-process
+ finished), this function returns -1.
This function is called by QIODevice. Reimplement this function
when creating a subclass of QIODevice.
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index e11cef9..a45225f 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -221,6 +221,24 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list
return env;
}
+QStringList QProcessEnvironmentPrivate::keys() const
+{
+ QStringList result;
+ QHash<Unit, Unit>::ConstIterator it = hash.constBegin(),
+ end = hash.constEnd();
+ for ( ; it != end; ++it)
+ result << nameToString(it.key());
+ return result;
+}
+
+void QProcessEnvironmentPrivate::insert(const Hash &h)
+{
+ QHash<Unit, Unit>::ConstIterator it = h.constBegin(),
+ end = h.constEnd();
+ for ( ; it != end; ++it)
+ hash.insert(it.key(), it.value());
+}
+
/*!
Creates a new QProcessEnvironment object. This constructor creates an
empty environment. If set on a QProcess, this will cause the current
@@ -396,6 +414,33 @@ QStringList QProcessEnvironment::toStringList() const
return d ? d->toList() : QStringList();
}
+/*!
+ \since 4.8
+
+ Returns a list containing all the variable names in this QProcessEnvironment
+ object.
+*/
+QStringList QProcessEnvironment::keys() const
+{
+ return d ? d->keys() : QStringList();
+}
+
+/*!
+ \overload
+ \since 4.8
+
+ Inserts the contents of \a e in this QProcessEnvironment object. Variables in
+ this object that also exist in \a e will be overwritten.
+*/
+void QProcessEnvironment::insert(const QProcessEnvironment &e)
+{
+ if (!e.d)
+ return;
+
+ // d detaches from null
+ d->insert(e.d->hash);
+}
+
void QProcessPrivate::Channel::clear()
{
switch (type) {
@@ -2082,6 +2127,9 @@ void QProcess::terminate()
On Symbian, this function requires platform security capability
\c PowerMgmt. If absent, the process will panic with KERN-EXEC 46.
+ \note Killing running processes from other processes will typically
+ cause a panic in Symbian due to platform security.
+
\sa {Symbian Platform Security Requirements}
\sa terminate()
*/
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h
index baa67f7..664992f 100644
--- a/src/corelib/io/qprocess.h
+++ b/src/corelib/io/qprocess.h
@@ -87,6 +87,10 @@ public:
QStringList toStringList() const;
+ QStringList keys() const;
+
+ void insert(const QProcessEnvironment &e);
+
static QProcessEnvironment systemEnvironment();
private:
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index be4f2a0..7bfcb31 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -94,6 +94,8 @@ public:
static QProcessEnvironment fromList(const QStringList &list);
QStringList toList() const;
+ QStringList keys() const;
+ void insert(const Hash &hash);
};
class QProcessPrivate : public QIODevicePrivate
diff --git a/src/corelib/io/qprocess_symbian.cpp b/src/corelib/io/qprocess_symbian.cpp
index d22d1ed..8a74c7b 100644
--- a/src/corelib/io/qprocess_symbian.cpp
+++ b/src/corelib/io/qprocess_symbian.cpp
@@ -961,16 +961,15 @@ bool QProcessPrivate::waitForFinished(int msecs)
User::WaitForRequest(logonStatus, timerStatus);
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished() - Wait completed");
- if (timerStatus == KErrNone)
+ if (logonStatus != KRequestPending) {
+ timer.Cancel();
+ User::WaitForRequest(timerStatus);
+ } else {
timeoutOccurred = true;
-
- timer.Cancel();
+ symbianProcess->LogonCancel(logonStatus);
+ User::WaitForRequest(logonStatus);
+ }
timer.Close();
-
- symbianProcess->LogonCancel(logonStatus);
-
- // Eat cancel request completion so that it won't mess up main thread scheduling later
- User::WaitForRequest(logonStatus, timerStatus);
}
} else {
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished(), qt_rprocess_running returned false");
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index ba61bda..b7505ce 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -493,8 +493,8 @@ static char **_q_dupEnvironment(const QHash<QByteArray, QByteArray> &environment
}
if (needToAddLibraryPath)
- envp[(*envc)++] = ::strdup(QByteArray(libraryPath) + '=' +
- envLibraryPath);
+ envp[(*envc)++] = ::strdup(QByteArray(QByteArray(libraryPath) + '=' +
+ envLibraryPath).constData());
return envp;
}
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index 0435256..cd8c1a3 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -373,7 +373,7 @@ QResourcePrivate::ensureChildren() const
Constructs a QResource pointing to \a file. \a locale is used to
load a specific localization of a resource data.
- \sa QFileInfo, searchPaths(), setFileName(), setLocale()
+ \sa QFileInfo, QDir::searchPaths(), setFileName(), setLocale()
*/
QResource::QResource(const QString &file, const QLocale &locale) : d_ptr(new QResourcePrivate(this))
@@ -418,7 +418,7 @@ QLocale QResource::locale() const
/*!
Sets a QResource to point to \a file. \a file can either be absolute,
in which case it is opened directly, if relative then the file will be
- tried to be found in searchPaths().
+ tried to be found in QDir::searchPaths().
\sa absoluteFilePath()
*/
@@ -446,7 +446,7 @@ QString QResource::fileName() const
/*!
Returns the real path that this QResource represents, if the resource
- was found via the searchPaths() it will be indicated in the path.
+ was found via the QDir::searchPaths() it will be indicated in the path.
\sa fileName()
*/
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 56ed746..b5e5808 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -49,11 +49,8 @@
#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
-#include <stdlib.h>
#if !defined(Q_OS_WINCE)
# include <errno.h>
-# include <sys/stat.h>
-# include <sys/types.h>
#endif
#include <stdlib.h>
@@ -64,19 +61,8 @@
# include "private/qcore_unix_p.h" // overrides QT_OPEN
#endif
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
-# include <process.h>
-# if defined(_MSC_VER) && _MSC_VER >= 1400
-# include <share.h>
-# endif
-#endif
-
-#if defined(Q_OS_WINCE)
-# include <types.h>
-#endif
-
-#if defined(Q_OS_VXWORKS)
-# include <taskLib.h>
+#if defined(QT_BUILD_CORE_LIB)
+#include "qcoreapplication.h"
#endif
QT_BEGIN_NAMESPACE
@@ -109,167 +95,75 @@ QT_BEGIN_NAMESPACE
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-static int _gettemp(char *path, int *doopen, int domkdir, int slen)
-{
- char *start, *trv, *suffp;
- QT_STATBUF sbuf;
- int rval;
-#if defined(Q_OS_WIN)
- int pid;
-#else
- pid_t pid;
-#endif
-
- if (doopen && domkdir) {
- errno = EINVAL;
- return 0;
- }
- for (trv = path; *trv; ++trv)
- ;
- trv -= slen;
- suffp = trv;
- --trv;
- if (trv < path) {
- errno = EINVAL;
- return 0;
- }
-#if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
- pid = _getpid();
-#elif defined(Q_OS_VXWORKS)
- pid = (pid_t) taskIdCurrent;
-#else
- pid = getpid();
-#endif
- while (trv >= path && *trv == 'X' && pid != 0) {
- *trv-- = (pid % 10) + '0';
- pid /= 10;
- }
+/*!
+ \internal
-#ifndef S_ISDIR
-# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
+ Generates a unique file path and returns a native handle to the open file.
+ \a path is used as a template when generating unique paths,
+ \a placeholderStart and \a placeholderEnd delimit the sub-string that will
+ be randomized.
- while (trv >= path && *trv == 'X') {
- char c;
+ Returns an open handle to the newly created file if successful, an invalid
+ handle otherwise. In both cases, the string in \a path will be changed and
+ contain the generated path name.
+*/
+static int createFileFromTemplate(char *const path,
+ char *const placeholderStart, char *const placeholderEnd)
+{
+ Q_ASSERT(placeholderEnd > placeholderStart);
- // CHANGE arc4random() -> random()
- pid = (qrand() & 0xffff) % (26+26);
- if (pid < 26)
- c = pid + 'A';
- else
- c = (pid - 26) + 'a';
- *trv-- = c;
- }
- start = trv + 1;
-
- /*
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
- */
- if (doopen || domkdir) {
- for (;; --trv) {
- if (trv <= path)
- break;
- if (*trv == '/') {
- *trv = '\0';
-#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
- if (trv - path == 2 && path[1] == ':') {
- // Special case for Windows drives
- // (e.g., "C:" => "C:\").
- // ### Better to use a Windows
- // call for this.
- char drive[] = "c:\\";
- drive[0] = path[0];
- rval = QT_STAT(drive, &sbuf);
- } else
+ // Initialize placeholder with random chars + PID.
+ {
+ char *rIter = placeholderEnd;
+
+#if defined(QT_BUILD_CORE_LIB)
+ qint64 pid = QCoreApplication::applicationPid();
+ do {
+ *--rIter = (pid % 10) + '0';
+ pid /= 10;
+ } while (rIter != placeholderStart && pid != 0);
#endif
- rval = QT_STAT(path, &sbuf);
- *trv = '/';
- if (rval != 0)
- return 0;
- if (!S_ISDIR(sbuf.st_mode)) {
- errno = ENOTDIR;
- return 0;
- }
- break;
- }
+
+ while (rIter != placeholderStart) {
+ char ch = char((qrand() & 0xffff) % (26 + 26));
+ if (ch < 26)
+ *--rIter = ch + 'A';
+ else
+ *--rIter = ch - 26 + 'a';
}
}
for (;;) {
- if (doopen) {
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
- if (_sopen_s(doopen, path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR|QT_OPEN_BINARY
-# ifdef QT_LARGEFILE_SUPPORT
- |QT_OPEN_LARGEFILE
-# endif
- , _SH_DENYNO, _S_IREAD | _S_IWRITE)== 0)
-#else // WIN && !CE
-# if defined(Q_OS_WINCE)
- QString targetPath;
- if (QDir::isAbsolutePath(QString::fromLatin1(path)))
- targetPath = QLatin1String(path);
- else
- targetPath = QDir::currentPath().append(QLatin1Char('/')) + QLatin1String(path);
-
- if ((*doopen =
- QT_OPEN(targetPath.toLocal8Bit(), O_CREAT|O_EXCL|O_RDWR
-# else // CE
- // this is Unix or older MSVC
- if ((*doopen =
- QT_OPEN(path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR
-# endif
-# ifdef QT_LARGEFILE_SUPPORT
- |QT_OPEN_LARGEFILE
-# endif
-# if defined(Q_OS_WINCE)
- |_O_BINARY
-# elif defined(Q_OS_WIN)
- |O_BINARY
-# endif
- , 0600)) >= 0)
-#endif // WIN && !CE
- {
- return 1;
- }
- if (errno != EEXIST)
- return 0;
- } else if (domkdir) {
-#ifdef Q_OS_WIN
- if (QT_MKDIR(path) == 0)
-#else
- if (QT_MKDIR(path, 0700) == 0)
-#endif
- return 1;
+ // Atomically create file and obtain handle
+#ifndef Q_OS_WIN
+ {
+ int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
+ if (fd != -1)
+ return fd;
if (errno != EEXIST)
- return 0;
+ return -1;
}
-#ifndef Q_OS_WIN
- else if (QT_LSTAT(path, &sbuf))
- return (errno == ENOENT) ? 1 : 0;
#else
if (!QFileInfo(QLatin1String(path)).exists())
return 1;
#endif
/* tricky little algorwwithm for backward compatibility */
- for (trv = start;;) {
- if (!*trv)
- return 0;
- if (*trv == 'Z') {
- if (trv == suffp)
- return 0;
- *trv++ = 'a';
+ for (char *iter = placeholderStart;;) {
+ // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
+ // String progression: "ZZaiC" => "aabiC"
+ if (*iter == 'Z') {
+ *iter++ = 'a';
+ if (iter == placeholderEnd)
+ return -1;
} else {
- if (isdigit(*trv))
- *trv = 'a';
- else if (*trv == 'z') /* inc from z to A */
- *trv = 'A';
+ if (isdigit(*iter))
+ *iter = 'a';
+ else if (*iter == 'z') /* inc from z to A */
+ *iter = 'A';
else {
- if (trv == suffp)
- return 0;
- ++*trv;
+ ++*iter;
}
break;
}
@@ -278,14 +172,6 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
/*NOTREACHED*/
}
-#ifndef Q_WS_WIN
-static int qt_mkstemps(char *path, int slen)
-{
- int fd = 0;
- return (_gettemp(path, &fd, 0, slen) ? fd : -1);
-}
-#endif
-
//************* QTemporaryFileEngine
class QTemporaryFileEngine : public QFSFileEngine
{
@@ -363,14 +249,49 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
return QFSFileEngine::open(openMode);
QString qfilename = d->fileEntry.filePath();
- if(!qfilename.contains(QLatin1String("XXXXXX")))
- qfilename += QLatin1String(".XXXXXX");
- int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- char *filename = qstrdup(qfilename.toLocal8Bit());
+ // Find placeholder string.
+ uint phPos = qfilename.length();
+ uint phLength = 0;
-#ifndef Q_WS_WIN
- int fd = qt_mkstemps(filename, suffixLength);
+ while (phPos != 0) {
+ --phPos;
+
+ if (qfilename[phPos] == QLatin1Char('X')) {
+ ++phLength;
+ continue;
+ }
+
+ if (qfilename[phPos] == QLatin1Char('/')
+ || phLength >= 6) {
+ ++phPos;
+ break;
+ }
+
+ phLength = 0;
+ }
+
+ QStringRef prefix, suffix;
+ if (phLength < 6) {
+ qfilename += QLatin1Char('.');
+ prefix = QStringRef(&qfilename);
+ phLength = 6;
+ } else {
+ prefix = qfilename.leftRef(phPos);
+ suffix = qfilename.midRef(phPos + phLength);
+ }
+
+ QByteArray filename = prefix.toLocal8Bit();
+ phPos = filename.length();
+ if (suffix.isEmpty())
+ filename.resize(phPos + phLength);
+ else
+ filename.insert(phPos + phLength, suffix.toLocal8Bit());
+
+ char *path = filename.data();
+
+#ifndef Q_OS_WIN
+ int fd = createFileFromTemplate(path, path + phPos, path + phPos + phLength);
if (fd != -1) {
// First open the fd as an external file descriptor to
// initialize the engine properly.
@@ -380,26 +301,22 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
d->closeFileHandle = true;
// Restore the file names (open() resets them).
- d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename)); //note that filename is NOT a native path
+ d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); //note that filename is NOT a native path
filePathIsTemplate = false;
- delete [] filename;
return true;
}
QT_CLOSE(fd);
}
- delete [] filename;
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
return false;
#else
- if (!_gettemp(filename, 0, 0, suffixLength)) {
- delete [] filename;
+ if (createFileFromTemplate(path, path + phPos, path + phPos + phLength) == -1) {
return false;
}
QString template_ = d->fileEntry.filePath();
- d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename));
- delete [] filename;
+ d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length()));
if (QFSFileEngine::open(openMode)) {
filePathIsTemplate = false;