VirtualBox

Changeset 6994 in vbox


Ignore:
Timestamp:
Feb 18, 2008 2:02:10 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
28189
Message:

Restrict RTFILE_O_NOT_CONTENT_INDEXED to file creation. Rearranged the reorder the code a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r6992 r6994  
    227227                              dwFlagsAndAttributes,
    228228                              NULL);
    229     if (hFile == INVALID_HANDLE_VALUE)
    230         return RTErrConvertFromWin32(GetLastError());
    231 
    232     /*
    233      * Turn off indexing of directory through Windows Indexing Service.
    234      */
    235     if (fOpen & RTFILE_O_NOT_CONTENT_INDEXED)
    236     {
    237         if (!SetFileAttributes(pszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
    238         {
    239             rc = RTErrConvertFromWin32(GetLastError());
    240             CloseHandle(hFile);
    241             return rc;
    242         }
    243     }
    244229#else
    245 
    246230    PRTUCS2 pwszFilename;
    247231    rc = RTStrToUtf16(pszFilename, &pwszFilename);
     
    256240                               dwFlagsAndAttributes,
    257241                               NULL);
    258     if (hFile == INVALID_HANDLE_VALUE)
    259     {
    260         rc = RTErrConvertFromWin32(GetLastError()); /* get error first! */
    261         RTUtf16Free(pwszFilename);
    262         return rc;
    263     }
    264 
    265     /*
    266      * Turn off indexing of directory through Windows Indexing Service.
    267      */
    268     if (fOpen & RTFILE_O_NOT_CONTENT_INDEXED)
    269     {
    270         if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
     242#endif
     243    if (hFile != INVALID_HANDLE_VALUE)
     244    {
     245        bool fCreated = dwCreationDisposition == CREATE_ALWAYS
     246                     || dwCreationDisposition == CREATE_NEW
     247                     || (dwCreationDisposition == OPEN_ALWAYS && GetLastError() == 0);
     248
     249        /*
     250         * Turn off indexing of directory through Windows Indexing Service.
     251         */
     252        if (    fCreated
     253            &&  (fOpen & RTFILE_O_NOT_CONTENT_INDEXED))
    271254        {
    272             rc = RTErrConvertFromWin32(GetLastError());
    273             CloseHandle(hFile);
     255#ifdef RT_DONT_CONVERT_FILENAMES
     256            if (!SetFileAttributes(pszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
     257#else
     258            if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
     259#endif
     260                rc = RTErrConvertFromWin32(GetLastError());
     261        }
     262        /*
     263         * Do we need to truncate the file?
     264         */
     265        else if (    !fCreated
     266                 &&     (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK))
     267                     == (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE))
     268        {
     269            if (!SetEndOfFile(hFile))
     270                rc = RTErrConvertFromWin32(GetLastError());
     271        }
     272        if (RT_SUCCESS(rc))
     273        {
     274            *pFile = (RTFILE)hFile;
     275            Assert((HANDLE)*pFile == hFile);
     276#ifndef RT_DONT_CONVERT_FILENAMES
    274277            RTUtf16Free(pwszFilename);
    275             return rc;
     278#endif
     279            return VINF_SUCCESS;
    276280        }
    277     }
    278 
     281
     282        CloseHandle(hFile);
     283    }
     284    else
     285        rc = RTErrConvertFromWin32(GetLastError());
     286#ifndef RT_DONT_CONVERT_FILENAMES
    279287    RTUtf16Free(pwszFilename);
    280288#endif
    281 
    282     /*
    283      * Do we need to truncate the file?
    284      */
    285     if (    (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK))
    286         ==  (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE))
    287     {
    288         if (!SetEndOfFile(hFile))
    289         {
    290             rc = RTErrConvertFromWin32(GetLastError()); /* get error first! */
    291             CloseHandle(hFile);
    292             return rc;
    293         }
    294     }
    295 
    296     *pFile = (RTFILE)hFile;
    297     Assert((HANDLE)*pFile == hFile);
    298     return VINF_SUCCESS;
     289    return rc;
    299290}
    300291
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette