summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2010-03-09 13:57:25 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-03-09 15:46:30 (GMT)
commitaa235c3cf623f832c01df9a4065375ca610d4d06 (patch)
treec208876508f9c1ce5c5fe16c0ba3fd0d8dad842a
parent6fb8d8af7cc9d3f7e90c0534aa2ec90dd7289176 (diff)
downloadQt-aa235c3cf623f832c01df9a4065375ca610d4d06.zip
Qt-aa235c3cf623f832c01df9a4065375ca610d4d06.tar.gz
Qt-aa235c3cf623f832c01df9a4065375ca610d4d06.tar.bz2
QFSFileEngine: Don't use owner's permissions for current user; calculate them instead
Having this code in the engine allows cleaning up the hack in QFileInfo. Merge-request: 428 Reviewed-by: João Abecasis <joao@trolltech.com>
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp14
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp20
2 files changed, 22 insertions, 12 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 8841fea..d63a088 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -749,12 +749,6 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
ret |= QAbstractFileEngine::WriteOwnerPerm;
if (st.st_mode & S_IXUSR)
ret |= QAbstractFileEngine::ExeOwnerPerm;
- if (st.st_mode & S_IRUSR)
- ret |= QAbstractFileEngine::ReadUserPerm;
- if (st.st_mode & S_IWUSR)
- ret |= QAbstractFileEngine::WriteUserPerm;
- if (st.st_mode & S_IXUSR)
- ret |= QAbstractFileEngine::ExeUserPerm;
if (st.st_mode & S_IRGRP)
ret |= QAbstractFileEngine::ReadGroupPerm;
if (st.st_mode & S_IWGRP)
@@ -768,6 +762,14 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
if (st.st_mode & S_IXOTH)
ret |= QAbstractFileEngine::ExeOtherPerm;
+ // calculate user permissions
+ if (QT_ACCESS(nativeFilePath.constData(), R_OK) == 0)
+ ret |= QAbstractFileEngine::ReadUserPerm;
+ if (QT_ACCESS(nativeFilePath.constData(), W_OK) == 0)
+ ret |= QAbstractFileEngine::WriteUserPerm;
+ if (QT_ACCESS(nativeFilePath.constData(), X_OK) == 0)
+ ret |= QAbstractFileEngine::ExeUserPerm;
+
return ret;
}
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 72eb081..ecfb17a 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -1480,12 +1480,12 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
//### what to do with permissions if we don't use NTFS
// for now just add all permissions and what about exe missions ??
// also qt_ntfs_permission_lookup is now not set by default ... should it ?
- ret |= QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm
- | QAbstractFileEngine::ReadGroupPerm | QAbstractFileEngine::ReadOtherPerm;
+ ret |= QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadGroupPerm
+ | QAbstractFileEngine::ReadOtherPerm;
if (!(fileAttrib & FILE_ATTRIBUTE_READONLY)) {
- ret |= QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm
- | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm;
+ ret |= QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteGroupPerm
+ | QAbstractFileEngine::WriteOtherPerm;
}
QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath;
@@ -1493,9 +1493,17 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
if ((fileAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") ||
ext == QLatin1String(".pif") || ext == QLatin1String(".cmd")) {
- ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm |
- QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::ExeUserPerm;
+ ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm
+ | QAbstractFileEngine::ExeOtherPerm;
}
+
+ // calculate user permissions
+ if (::_waccess((wchar_t*)longFileName(filePath).utf16(), R_OK) == 0)
+ ret |= QAbstractFileEngine::ReadUserPerm;
+ if (::_waccess((wchar_t*)longFileName(filePath).utf16(), W_OK) == 0)
+ ret |= QAbstractFileEngine::WriteUserPerm;
+ if (::_waccess((wchar_t*)longFileName(filePath).utf16(), X_OK) == 0)
+ ret |= QAbstractFileEngine::ExeUserPerm;
}
return ret;
}