diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2010-10-04 13:22:25 +0100 |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2010-10-07 14:36:02 +0100 |
commit | b7bc57cca9e34d3622afc1c1a9ff322024f350df (patch) | |
tree | e444cd70309976c853f1f2df8231e76b88d7dbb6 /src/corelib/io/qfilesystemengine_unix.cpp | |
parent | 71f04c22f128a52353f0a53d6d118375c0e99e33 (diff) |
Implement error reporting for file APIs
Part of the refactoring broke error reporting (false would be return on
failure, but the QFile::error() would not return the right thing)
A string is passed to the QFileSystemEngine functions which need to return
an error, and filled in via the error code when a function fails.
For windows, this is GetLastError() as for the previous workaround
For unix, this is errno, as for the previous workaround
For symbian, this is the integer error code returned by the function
Reviewed-By: Thomas Zander
Reviewed-By: Prasanth Ullattil
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 1dee09b2ee..7c733c465c 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -572,34 +572,45 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo } //static -bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target) +bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) { - return (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0); + if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) + return true; + errorString = qt_error_string(errno); + return false; } //static -bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target) +bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) { Q_UNUSED(source); Q_UNUSED(target); // # we can implement this using sendfile(2) + errorString = QLatin1String("Not implemented!") return false; } //static -bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target) +bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) { - return (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0); + if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) + return true; + errorString = qt_error_string(errno); + return false; } //static -bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry) +bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QString &errorString) { - return (unlink(entry.nativeFilePath().constData()) == 0); + if (unlink(entry.nativeFilePath().constData()) == 0) + return true; + errorString = qt_error_string(errno); + return false; + } //static -bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QFileSystemMetaData *data) +bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QString &errorString, QFileSystemMetaData *data) { mode_t mode = 0; if (permissions & QFile::ReadOwner) @@ -633,6 +644,8 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions)); data->knownFlagsMask |= QFileSystemMetaData::Permissions; } + if (!success) + errorString = qt_error_string(errno); return success; } |