Ignore:
Timestamp:
Jun 7, 2009, 6:38:05 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: QFSFileEngine: Iimplemented OS/2 versions of homePath(), rootPath(), tempPath() and isRelativePath(). Removed confusing code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qfsfileengine_os2.cpp

    r18 r20  
    6464#include <grp.h>
    6565
     66
     67
    6668QT_BEGIN_NAMESPACE
    6769
     
    374376bool QFSFileEngine::copy(const QString &)
    375377{
    376     // ### Add copy code for Unix here
     378    // ### Add copy code for here
    377379    return false;
    378380}
     
    420422        return true;
    421423    }
    422 #if defined(Q_OS_DARWIN)  // Mac X doesn't support trailing /'s
    423     if (dirName[dirName.length() - 1] == QLatin1Char('/'))
    424         dirName = dirName.left(dirName.length() - 1);
    425 #endif
    426424    return (::mkdir(QFile::encodeName(dirName), 0777) == 0);
    427425}
     
    493491{
    494492    QString home = QFile::decodeName(qgetenv("HOME"));
    495     if (home.isNull())
    496         home = rootPath();
     493    if (home.isEmpty()) {
     494        home = QFile::decodeName(qgetenv("HOMEDRIVE")) +
     495               QFile::decodeName(qgetenv("HOMEPATH"));
     496        if (home.isEmpty())
     497            home = rootPath();
     498    }
    497499    return home;
    498500}
     
    500502QString QFSFileEngine::rootPath()
    501503{
    502     return QString::fromLatin1("/");
     504    ULONG bootDrive = 0;
     505    DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PVOID)&bootDrive,
     506                    sizeof(bootDrive));
     507    QString root = QChar((char)(bootDrive + 'A' - 1));
     508    root += ":/";
     509    return root;
    503510}
    504511
    505512QString QFSFileEngine::tempPath()
    506513{
    507     QString temp = QFile::decodeName(qgetenv("TMPDIR"));
    508     if (temp.isEmpty())
    509         temp = QString::fromLatin1("/tmp/");
     514    QString temp = QFile::decodeName(qgetenv("TEMP"));
     515    if (temp.isEmpty()) {
     516        temp = QFile::decodeName(qgetenv("TMP"));
     517        if (temp.isEmpty()) {
     518            temp = QFile::decodeName(qgetenv("TMPDIR"));
     519            if (temp.isEmpty())
     520                temp = rootPath() + "tmp";
     521        }
     522    }
    510523    return temp;
    511524}
     
    514527{
    515528    QFileInfoList ret;
    516     ret.append(rootPath());
     529
     530        ULONG driveBits, dummy;
     531        DosQueryCurrentDisk( &dummy, &driveBits );
     532        driveBits &= 0x3ffffff;
     533
     534        char driveName[4];
     535        qstrcpy( driveName, "A:/" );
     536
     537        while( driveBits ) {
     538            if ( driveBits & 1 )
     539                ret.append(QString::fromLatin1(driveName).toUpper());
     540            driveName[0]++;
     541            driveBits = driveBits >> 1;
     542        }
     543
    517544    return ret;
    518545}
     
    546573    return is_link;
    547574}
    548 
    549 #if !defined(QWS) && defined(Q_OS_MAC)
    550 static bool _q_isMacHidden(const QString &path)
    551 {
    552     OSErr err = noErr;
    553 
    554     FSRef fsRef;
    555 
    556 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    557     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    558         err = FSPathMakeRefWithOptions(reinterpret_cast<const UInt8 *>(QFile::encodeName(QDir::cleanPath(path)).constData()),
    559                                         kFSPathMakeRefDoNotFollowLeafSymlink, &fsRef, 0);
    560     } else
    561 #endif
    562     {
    563         QFileInfo fi(path);
    564         FSRef parentRef;
    565         err = FSPathMakeRef(reinterpret_cast<const UInt8 *>(fi.absoluteDir().absolutePath().toUtf8().constData()),
    566                             &parentRef, 0);
    567         if (err == noErr) {
    568             QString fileName = fi.fileName();
    569             err = FSMakeFSRefUnicode(&parentRef, fileName.length(),
    570                                      reinterpret_cast<const UniChar *>(fileName.unicode()),
    571                                      kTextEncodingUnknown, &fsRef);
    572         }
    573     }
    574     if (err != noErr)
    575         return false;
    576 
    577     FSCatalogInfo catInfo;
    578     err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
    579     if (err != noErr)
    580         return false;
    581 
    582     FileInfo * const fileInfo = reinterpret_cast<FileInfo*>(&catInfo.finderInfo);
    583     bool result = (fileInfo->finderFlags & kIsInvisible);
    584     return result;
    585 }
    586 #endif
    587575
    588576/*!
     
    630618    }
    631619    if (type & TypesMask) {
    632 #if !defined(QWS) && defined(Q_OS_MAC)
    633         bool foundAlias = false;
    634         {
    635             FSRef fref;
    636             if (FSPathMakeRef((const UInt8 *)QFile::encodeName(QDir::cleanPath(d->filePath)).data(),
    637                              &fref, NULL) == noErr) {
    638                 Boolean isAlias, isFolder;
    639                 if (FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr && isAlias) {
    640                     foundAlias = true;
    641                     ret |= LinkType;
    642                 }
    643             }
    644         }
    645         if (!foundAlias)
    646 #endif
    647620        {
    648621            if ((type & LinkType) && d->isSymlink())
     
    652625            else if (exists && (d->st.st_mode & S_IFMT) == S_IFDIR)
    653626                ret |= DirectoryType;
    654 #if !defined(QWS) && defined(Q_OS_MAC)
    655             if((ret & DirectoryType) && (type & BundleType)) {
    656                 QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(d->filePath),
    657                                                                       kCFURLPOSIXPathStyle, true);
    658                 UInt32 type, creator;
    659                 if(CFBundleGetPackageInfoInDirectory(url, &type, &creator))
    660                     ret |= BundleType;
    661             }
    662 #endif
    663627        }
    664628    }
     
    667631        if (exists)
    668632            ret |= ExistsFlag;
    669         if (fileName(BaseName)[0] == QLatin1Char('.')
    670 #if !defined(QWS) && defined(Q_OS_MAC)
    671             || _q_isMacHidden(d->filePath)
    672 #endif
    673         )
     633        if (fileName(BaseName)[0] == QLatin1Char('.'))
    674634            ret |= HiddenFlag;
    675635        if (d->filePath == QLatin1String("/"))
     
    683643    Q_D(const QFSFileEngine);
    684644    if (file == BundleName) {
    685 #if !defined(QWS) && defined(Q_OS_MAC)
    686         QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(d->filePath),
    687                                                               kCFURLPOSIXPathStyle, true);
    688         if(CFDictionaryRef dict = CFBundleCopyInfoDictionaryForURL(url)) {
    689             if(CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) {
    690                 if(CFGetTypeID(name) == CFStringGetTypeID())
    691                     return QCFString::toQString((CFStringRef)name);
    692             }
    693         }
    694 #endif
    695645        return QString();
    696646    } else if (file == BaseName) {
     
    783733                ret += QFile::decodeName(QByteArray(s));
    784734#if defined(__GLIBC__) && !defined(PATH_MAX)
    785                 ::free(s);
     735::free(s);
    786736#endif
    787737
     
    800750            }
    801751        }
    802 #if !defined(QWS) && defined(Q_OS_MAC)
    803         {
    804             FSRef fref;
    805             if (FSPathMakeRef((const UInt8 *)QFile::encodeName(QDir::cleanPath(d->filePath)).data(), &fref, 0) == noErr) {
    806                 Boolean isAlias, isFolder;
    807                 if (FSResolveAliasFile(&fref, true, &isFolder, &isAlias) == noErr && isAlias) {
    808                     AliasHandle alias;
    809                     if (FSNewAlias(0, &fref, &alias) == noErr && alias) {
    810                         CFStringRef cfstr;
    811                         if (FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr)
    812                             return QCFString::toQString(cfstr);
    813                     }
    814                 }
    815             }
    816         }
    817 #endif
    818752        return QString();
    819753    }
     
    824758{
    825759    Q_D(const QFSFileEngine);
    826     int len = d->filePath.length();
    827     if (len == 0)
    828         return true;
    829     return d->filePath[0] != QLatin1Char('/');
     760   
     761   
     762       
     763   
    830764}
    831765
     
    845779QString QFSFileEngine::owner(FileOwner own) const
    846780{
    847 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
     781#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
    848782    int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
    849783    if (size_max == -1)
     
    854788    if (own == OwnerUser) {
    855789        struct passwd *pw = 0;
    856 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
     790#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
    857791        struct passwd entry;
    858792        getpwuid_r(ownerId(own), &entry, buf.data(), buf.size(), &pw);
     
    864798    } else if (own == OwnerGroup) {
    865799        struct group *gr = 0;
    866 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
     800#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
    867801        size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
    868802        if (size_max == -1)
Note: See TracChangeset for help on using the changeset viewer.