Index: kstandarddirs.cpp =================================================================== RCS file: /home/kde/kdelibs/kdecore/kstandarddirs.cpp,v retrieving revision 1.151.2.3 diff -u -p -r1.151.2.3 kstandarddirs.cpp --- kdecore/kstandarddirs.cpp 16 Jun 2003 09:31:43 -0000 1.151.2.3 +++ kdecore/kstandarddirs.cpp 25 Jul 2004 14:34:48 -0000 @@ -537,71 +537,68 @@ KStandardDirs::realPath(const QString &d return dirname; } +void KStandardDirs::createSpecialResource(const char *type) +{ + char hostname[256]; + hostname[0] = 0; + gethostname(hostname, 255); + QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); + char link[1024]; + link[1023] = 0; + int result = readlink(QFile::encodeName(dir).data(), link, 1023); + bool relink = (result == -1) && (errno == ENOENT); + if ((result > 0) && (link[0] == '/')) + { + link[result] = 0; + struct stat stat_buf; + int res = lstat(link, &stat_buf); + if ((res == -1) && (errno == ENOENT)) + { + relink = true; + } + else if ((res == -1) || (!S_ISDIR(stat_buf.st_mode))) + { + fprintf(stderr, "Error: \"%s\" is not a directory.\n", link); + relink = true; + } + else if (stat_buf.st_uid != getuid()) + { + fprintf(stderr, "Error: \"%s\" is owned by uid %d instead of uid %d.\n", link, stat_buf.st_uid, getuid()); + relink = true; + } + } + if (relink) + { + QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); + if (srv.isEmpty()) + srv = findExe(QString::fromLatin1("lnusertemp")); + if (!srv.isEmpty()) + { + system(QFile::encodeName(srv)+" "+type); + result = readlink(QFile::encodeName(dir).data(), link, 1023); + } + } + if (result > 0) + { + link[result] = 0; + if (link[0] == '/') + dir = QFile::decodeName(link); + else + dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); + } + addResourceDir(type, dir+'/'); +} + QStringList KStandardDirs::resourceDirs(const char *type) const { QStringList *candidates = dircache.find(type); if (!candidates) { // filling cache if (strcmp(type, "socket") == 0) - { - char hostname[256]; - hostname[0] = 0; - gethostname(hostname, 255); - QString dir = QString("%1socket-%2").arg(localkdedir()).arg(hostname); - char link[1024]; - link[1023] = 0; - int result = readlink(QFile::encodeName(dir).data(), link, 1023); - if ((result == -1) && (errno == ENOENT)) - { - QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); - if (srv.isEmpty()) - srv = findExe(QString::fromLatin1("lnusertemp")); - if (!srv.isEmpty()) - { - system(QFile::encodeName(srv)+" socket"); - result = readlink(QFile::encodeName(dir).data(), link, 1023); - } - } - if (result > 0) - { - link[result] = 0; - if (link[0] == '/') - dir = QFile::decodeName(link); - else - dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); - } - const_cast(this)->addResourceDir("socket", dir+'/'); - } - if (strcmp(type, "tmp") == 0) - { - char hostname[256]; - hostname[0] = 0; - gethostname(hostname, 255); - QString dir = QString("%1tmp-%2").arg(localkdedir()).arg(hostname); - char link[1024]; - link[1023] = 0; - int result = readlink(QFile::encodeName(dir).data(), link, 1023); - if ((result == -1) && (errno == ENOENT)) - { - QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); - if (srv.isEmpty()) - srv = findExe(QString::fromLatin1("lnusertemp")); - if (!srv.isEmpty()) - { - system(QFile::encodeName(srv)+" tmp"); - result = readlink(QFile::encodeName(dir).data(), link, 1023); - } - } - if (result > 0) - { - link[result] = 0; - if (link[0] == '/') - dir = QFile::decodeName(link); - else - dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); - } - const_cast(this)->addResourceDir("tmp", dir+'/'); - } + const_cast(this)->createSpecialResource(type); + else if (strcmp(type, "tmp") == 0) + const_cast(this)->createSpecialResource(type); + QDir testdir; candidates = new QStringList(); Index: kstandarddirs.h =================================================================== RCS file: /home/kde/kdelibs/kdecore/kstandarddirs.h,v retrieving revision 1.100.2.1 diff -u -p -r1.100.2.1 kstandarddirs.h --- kdecore/kstandarddirs.h 8 Jan 2003 16:15:51 -0000 1.100.2.1 +++ kdecore/kstandarddirs.h 25 Jul 2004 14:34:49 -0000 @@ -553,6 +553,7 @@ public: void checkConfig() const; void applyDataRestrictions(const QString &) const; + void createSpecialResource(const char*); }; /**