summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_unix.cpp
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2010-09-17 14:05:04 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-09-20 14:46:16 (GMT)
commit63d50fdfa59cd198f7bf87f37770960e1b93945d (patch)
tree29b80604ce487d14e1675e82f5220d57a3fbde23 /src/corelib/io/qfilesystemengine_unix.cpp
parent768009af920c642834b1730136d9c8b156277c1d (diff)
downloadQt-63d50fdfa59cd198f7bf87f37770960e1b93945d.zip
Qt-63d50fdfa59cd198f7bf87f37770960e1b93945d.tar.gz
Qt-63d50fdfa59cd198f7bf87f37770960e1b93945d.tar.bz2
Move rootPath, homePath, tempPath, currentPath and setCurrentPath
Moved these functions inside the QFilesystemEngine and redirected the QFSFileEngine copies. Reviewed-By: joao
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 6290d68..8724b15 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -246,7 +246,7 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
QByteArray orig = entry.nativeFilePath();
QByteArray result;
if (orig.isEmpty() || !orig.startsWith('/')) {
- QFileSystemEntry cur(QFSFileEngine::currentPath());
+ QFileSystemEntry cur(currentPath());
result = cur.nativeFilePath();
}
if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) {
@@ -548,4 +548,59 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per
return false; // TODO implement;
}
+QString QFileSystemEngine::homePath()
+{
+ QString home = QFile::decodeName(qgetenv("HOME"));
+ if (home.isNull())
+ home = rootPath();
+ return QDir::cleanPath(home);
+}
+
+QString QFileSystemEngine::rootPath()
+{
+ return QLatin1String("/");
+}
+
+QString QFileSystemEngine::tempPath()
+{
+ QString temp = QFile::decodeName(qgetenv("TMPDIR"));
+ if (temp.isEmpty())
+ temp = QLatin1String("/tmp/");
+ return QDir::cleanPath(temp);
+}
+
+bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path)
+{
+ int r;
+ r = QT_CHDIR(path.nativeFilePath());
+ return r >= 0;
+}
+
+QFileSystemEntry QFileSystemEngine::currentPath()
+{
+ QFileSystemEntry result;
+ QT_STATBUF st;
+ if (QT_STAT(".", &st) == 0) {
+#if defined(__GLIBC__) && !defined(PATH_MAX)
+ char *currentName = ::get_current_dir_name();
+ if (currentName) {
+ result = QFile::decodeName(QByteArray(currentName));
+ ::free(currentName);
+ }
+#else
+ char currentName[PATH_MAX+1];
+ if (::getcwd(currentName, PATH_MAX))
+ result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
+# if defined(QT_DEBUG)
+ if (result.isEmpty())
+ qWarning("QFSFileEngine::currentPath: getcwd() failed");
+# endif
+#endif
+ } else {
+# if defined(QT_DEBUG)
+ qWarning("QFSFileEngine::currentPath: stat(\".\") failed");
+# endif
+ }
+ return result;
+}
QT_END_NAMESPACE