summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@sosco.com>2009-09-22 12:57:54 (GMT)
committerShane Kearns <shane.kearns@sosco.com>2009-09-22 14:32:16 (GMT)
commitb85f6a46650774e2422ab44f1f12751ada8d9373 (patch)
tree1a655f629f41ab3628c106e4d8a63c8f1b2f2491 /src
parent7a603159dbf5c1f931cfc257aab0239abaa1d4a1 (diff)
downloadQt-b85f6a46650774e2422ab44f1f12751ada8d9373.zip
Qt-b85f6a46650774e2422ab44f1f12751ada8d9373.tar.gz
Qt-b85f6a46650774e2422ab44f1f12751ada8d9373.tar.bz2
Fix "... may return wrong private dir if application is on Z:, not C:"
QT-805 QCoreApplication::applicationDirPath() may return wrong private dir if application is on Z:, not C: Remove the emulator ifdef, instead RFs::Drive is used to get the drive attributes (to see if it is ROM / read only) RFs::SystemDrive is used to get the system drive, which is C: on S60 phones, but in theory configurable. It is not needed to call Open() on RProcess to call functions on the current process - this eliminates some code. Elimated some unneeded code to check for Z: before creating prvate path (now, the if statement would always have evaluated the same) Task-number: QT-805 Reviewed-by: Miikka Heikkinen
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 9283730..c575509 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -1788,6 +1788,8 @@ bool QCoreApplicationPrivate::isTranslatorInstalled(QTranslator *translator)
In Symbian this function will return the application private directory,
not the path to executable itself, as those are always in \c {/sys/bin}.
+ If the application is in a read only drive, i.e. ROM, then the private path
+ on the system drive will be returned.
\sa applicationFilePath()
*/
@@ -1803,42 +1805,39 @@ QString QCoreApplication::applicationDirPath()
#if defined(Q_OS_SYMBIAN)
{
QString appPath;
- RProcess proc;
- TInt err = proc.Open(proc.Id());
+ RFs& fs = qt_s60GetRFs();
+ TChar driveChar;
+ QChar qDriveChar;
+ driveChar = (RProcess().FileName())[0];
+
+ //Check if the process is installed in a read only drive (typically ROM),
+ //and use the system drive (typically C:) if so.
+ TInt drive;
+ TDriveInfo driveInfo;
+ TInt err = fs.CharToDrive(driveChar, drive);
if (err == KErrNone) {
- QChar driveChar;
-#if defined(Q_CC_NOKIAX86)
- // In emulator, always resolve the private dir on C-drive
- driveChar = QLatin1Char('C');
-#else
- driveChar = QLatin1Char((proc.FileName())[0]);
-#endif
- proc.Close();
+ err = fs.Drive(driveInfo, drive);
+ }
+ if (err != KErrNone || (driveInfo.iDriveAtt & KDriveAttRom) || (driveInfo.iMediaAtt
+ & KMediaAttWriteProtected)) {
+ driveChar = fs.GetSystemDriveChar();
+ drive = fs.GetSystemDrive();
+ }
- driveChar = driveChar.toUpper();
+ qDriveChar = QChar(QLatin1Char(driveChar)).toUpper();
- TFileName privatePath;
- RFs& fs = qt_s60GetRFs();
- fs.PrivatePath(privatePath);
- appPath = qt_TDesC2QString(privatePath);
- appPath.prepend(QLatin1Char(':')).prepend(driveChar);
-
- // Create the appPath if it doesn't exist. Non-existing appPath will cause
- // Platform Security violations later on if the app doesn't have AllFiles capability.
- // Can't create appPath for ROM unfortunately, so applications meant for
- // ROM should always deploy something to their private dir to ensure appPath exists,
- // if the PlatSec violations are an issue.
- char driveDiff = QLatin1Char('Z').toLatin1() - driveChar.toLatin1();
- TInt driveId = EDriveZ - static_cast<TInt>(driveDiff);
- if (driveId != EDriveZ) {
- TInt err = fs.CreatePrivatePath(driveId);
- if (err != KErrNone)
- qWarning("QCoreApplication::applicationDirPath: Failed to create private path.");
- }
- }
+ TFileName privatePath;
+ fs.PrivatePath(privatePath);
+ appPath = qt_TDesC2QString(privatePath);
+ appPath.prepend(QLatin1Char(':')).prepend(qDriveChar);
+
+ // Create the appPath if it doesn't exist. Non-existing appPath will cause
+ // Platform Security violations later on if the app doesn't have AllFiles capability.
+ err = fs.CreatePrivatePath(drive);
+ if (err != KErrNone)
+ qWarning("QCoreApplication::applicationDirPath: Failed to create private path.");
- QFileInfo fi(appPath);
- d->cachedApplicationDirPath = fi.exists() ? fi.canonicalFilePath() : QString();
+ d->cachedApplicationDirPath = QFileInfo(appPath).path();
}
#else
d->cachedApplicationDirPath = QFileInfo(applicationFilePath()).path();