Changeset 612


Ignore:
Timestamp:
Feb 27, 2010, 12:21:56 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Always return true from QFileInfo::isRoot()/isDir() for paths referring to root directories of drives with no media and always return false from QFileInfo::exists() for them (fixes the original problem from #137). Also, don't lstat() on such paths since they are definitely not symlinks.

Location:
trunk/src/corelib/io
Files:
3 edited

Legend:

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

    r561 r612  
    114114    is_link = 0;
    115115#endif
    116 #if defined(Q_OS_OS2)
    117     not_ready = 0;
    118 #endif
    119116    openMode = QIODevice::NotOpen;
    120117    fd = -1;
  • trunk/src/corelib/io/qfsfileengine_os2.cpp

    r564 r612  
    138138}
    139139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
    140155static bool isRelativePath(const QString &path)
    141156{
     
    642657                // ready: an attempt to stat() on a removable drive with no
    643658                // media inserted will cause an unnecessary delay and noise.
    644                 not_ready = 0;
    645659                BYTE drv[3] = { filePath.at(0).cell(), ':', '\0' };
    646660                BYTE buf[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
     
    649663                APIRET arc = DosQueryFSAttach(drv, 0, FSAIL_QUERYNAME, pfsq,
    650664                                              &bufSize);
    651                 if (arc == ERROR_NOT_READY) {
    652                     // it must be a removable drive with no media in it
    653                     memset(&st, 0, sizeof(st));
    654                     st.st_mode = S_IFDIR | 0777;
    655                     not_ready = 1;
    656                     could_stat = true;
    657                 } else if (arc != NO_ERROR) {
     665                if (arc != NO_ERROR) {
    658666                    could_stat = false;
    659667                } else {
     
    676684        QFSFileEnginePrivate *that = const_cast<QFSFileEnginePrivate *>(this);
    677685        that->need_lstat = false;
    678         QT_STATBUF st;          // don't clobber our main one
    679         that->is_link = (QT_LSTAT(nativeFilePath.constData(), &st) == 0) ? S_ISLNK(st.st_mode) : false;
     686        if (isDriveRootPath(filePath) || isUncRootPath(filePath)) {
     687            is_link = false;        // drive/share names are never symlinks
     688        } else {
     689            QT_STATBUF st;          // don't clobber our main one
     690            that->is_link = (QT_LSTAT(nativeFilePath.constData(), &st) == 0) ?
     691                            S_ISLNK(st.st_mode) : false;
     692        }
    680693    }
    681694    return is_link;
     
    688701{
    689702    Q_D(const QFSFileEngine);
     703
    690704    // Force a stat, so that we're guaranteed to get up-to-date results
    691     if (type & QAbstractFileEngine::FileFlag(QAbstractFileEngine::Refresh)) {
     705    if (type & ) {
    692706        d->tried_stat = 0;
    693707        d->need_lstat = 1;
    694708    }
    695709
     710
     711
     712
    696713    QAbstractFileEngine::FileFlags ret = 0;
    697     bool exists = d->doStat();
    698     if (!exists && !d->isSymlink())
     714
     715    // flags that don't need doStat()
     716    if (type & FlagsMask) {
     717        ret |= LocalDiskFlag;
     718        if (isRoot)
     719            ret |= RootFlag;
     720    }
     721    if (type & TypesMask) {
     722        if (isRoot)
     723            ret |= DirectoryType;
     724        // note: drive/share names are never symlinks
     725        else if ((type & LinkType) && d->isSymlink())
     726            ret |= LinkType;
     727    }
     728
     729    if (!exists)
    699730        return ret;
    700731
    701     if (exists && (type & PermsMask)) {
     732    // flags that need doStat()
     733    if (type & PermsMask) {
    702734        if (d->st.st_mode & S_IRUSR)
    703735            ret |= ReadOwnerPerm;
     
    726758    }
    727759    if (type & TypesMask) {
    728         {
    729             if ((type & LinkType) && d->isSymlink())
    730                 ret |= LinkType;
    731             if (exists && (d->st.st_mode & S_IFMT) == S_IFREG)
    732                 ret |= FileType;
    733             else if (exists && (d->st.st_mode & S_IFMT) == S_IFDIR)
    734                 ret |= DirectoryType;
    735         }
     760        if ((d->st.st_mode & S_IFMT) == S_IFREG)
     761            ret |= FileType;
     762        else if ((d->st.st_mode & S_IFMT) == S_IFDIR)
     763            ret |= DirectoryType;
    736764    }
    737765    if (type & FlagsMask) {
    738         ret |= LocalDiskFlag;
    739         if (exists)
    740             ret |= ExistsFlag;
     766        ret |= ExistsFlag;
    741767        if (d->st.st_attr & FILE_HIDDEN)
    742768            ret |= HiddenFlag;
    743         if (isDriveRootPath(d->filePath))
    744             ret |= RootFlag;
    745     }
     769    }
     770
    746771    return ret;
    747772}
     
    10021027    Q_D(const QFSFileEngine);
    10031028    QDateTime ret;
    1004     if (d->doStat() && !d->not_ready) {
     1029    if (d->doStat()) {
    10051030        if (time == CreationTime)
    10061031            ret.setTime_t(d->st.st_ctime ? d->st.st_ctime : d->st.st_mtime);
  • trunk/src/corelib/io/qfsfileengine_p.h

    r561 r612  
    138138    mutable uint is_link : 1;
    139139#endif
    140 #if defined(Q_OS_OS2)
    141     mutable uint not_ready : 1;
    142 #endif
    143140
    144141    bool doStat() const;
Note: See TracChangeset for help on using the changeset viewer.