Changeset 1117 for trunk/src


Ignore:
Timestamp:
Mar 5, 2013, 11:30:56 PM (12 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Make QFileInfo returned by QDirIterator report symlinks properly.

In QT_OS2_USE_DOSFINDFIRST mode (which is ON now), we use
DosFindFirst which is unaware of symlinks and doesn't properly resolve that.
Given that in many other places kLIBC functions are used which handle symlinks
pretty well, this would completely confuse some apps like QFileDialog (see #284).

This fix removes this inconsistency.

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

Legend:

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

    r1116 r1117  
    5252#include <QtCore/qvariant.h>
    5353
     54#include <unistd.h>
    5455#ifndef QT_OS2_USE_DOSFINDFIRST
    5556#include <dirent.h>
    56 #include <unistd.h>
    5757#else
    5858#include <QtCore/qdatetime.h>
     
    360360    }
    361361
     362    // we have to use stat() to see if it's a kLIBC-like symlink
     363    QByteArray fn = QFile::encodeName(fileName);
     364    QT_STATBUF st;
     365    if ((QT_LSTAT(fn.constData(), &st) == 0) && S_ISLNK(st.st_mode))
     366    {
     367        char buf[PATH_MAX];
     368        if (realpath(fn.constData(), buf) != NULL)
     369        {
     370            d_ptr->fileFlags |= QAbstractFileEngine::LinkType;
     371            // query the real file instead of the symlink
     372            FILESTATUS3L fst;
     373            APIRET arc = DosQueryPathInfo(buf, FIL_STANDARDL, &fst, sizeof(fst));
     374            if (arc == NO_ERROR)
     375            {
     376                // replace the information in the find buffer
     377                ffb->fdateCreation = fst.fdateCreation;
     378                ffb->ftimeCreation = fst.ftimeCreation;
     379                ffb->fdateLastAccess = fst.fdateLastAccess;
     380                ffb->ftimeLastAccess = fst.ftimeLastAccess;
     381                ffb->fdateLastWrite = fst.fdateLastWrite;
     382                ffb->ftimeLastWrite = fst.ftimeLastWrite;
     383                ffb->cbFile = fst.cbFile;
     384                ffb->cbFileAlloc = fst.cbFileAlloc;
     385                ffb->attrFile = fst.attrFile;
     386            }
     387            else
     388            {
     389                // mark as broken symlink
     390                d_ptr->fileFlags &= ~QAbstractFileEngine::ExistsFlag;
     391            }
     392        }
     393    }
     394
    362395    if (ffb->attrFile & FILE_DIRECTORY)
    363396        d_ptr->fileFlags |= QAbstractFileEngine::DirectoryType;
  • trunk/src/corelib/io/qfsfileengine_os2.cpp

    r1112 r1117  
    4242****************************************************************************/
    4343
    44 // temporary, until struct dirent in kLIBC gets creation and access time fields
    45 #define QT_OS2_USE_DOSFINDFIRST
    46 
    4744#include "qplatformdefs.h"
    4845#include "qabstractfileengine.h"
     
    677674            is_link = false;        // drive/share names are never symlinks
    678675        } else {
    679 #ifdef QT_OS2_USE_DOSFINDFIRST
    680             is_link = false;
    681 #else
    682676            QT_STATBUF st;          // don't clobber our main one
    683677            that->is_link = (QT_LSTAT(nativeFilePath.constData(), &st) == 0) ?
    684678                            S_ISLNK(st.st_mode) : false;
    685 #endif
    686679        }
    687680    }
Note: See TracChangeset for help on using the changeset viewer.