VirtualBox

Ignore:
Timestamp:
Dec 11, 2019 2:36:06 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135422
Message:

VBoxExtPackHelperApp: Retry RTDirRename on windows in case of AV software scanning temporary or exiting directories while we install / remove then.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-helper-apps/VBoxExtPackHelperApp.cpp

    r80569 r82552  
    3737#include <iprt/string.h>
    3838#include <iprt/stream.h>
     39#include <iprt/thread.h>
    3940#include <iprt/utf16.h>
    4041#include <iprt/vfs.h>
     
    221222
    222223/**
     224 * Wrapper around RTDirRename that may retry the operation for up to 15 seconds
     225 * on windows to deal with AV software.
     226 */
     227static int CommonDirRenameWrapper(const char *pszSrc, const char *pszDst, uint32_t fFlags)
     228{
     229#ifdef RT_OS_WINDOWS
     230    uint64_t nsNow = RTTimeNanoTS();
     231    for (;;)
     232    {
     233        int rc = RTDirRename(pszSrc, pszDst, fFlags);
     234        if (   (   rc == VERR_ACCESS_DENIED
     235                || rc == VERR_SHARING_VIOLATION)
     236            && RTTimeNanoTS() - nsNow < RT_NS_15SEC)
     237            return rc;
     238        RTThreadSleep(128);
     239    }
     240#else
     241    return RTDirRename(pszSrc, pszDst, fFlags);
     242#endif
     243}
     244
     245/**
    223246 * Common uninstall worker used by both uninstall and install --replace.
    224247 *
     
    237260        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to construct temporary extension pack path: %Rrc", rc);
    238261
    239     rc = RTDirRename(pszExtPackDir, szExtPackUnInstDir, RTPATHRENAME_FLAGS_NO_REPLACE);
     262    rc = CommonDirRenameWrapper(pszExtPackDir, szExtPackUnInstDir, RTPATHRENAME_FLAGS_NO_REPLACE);
    240263    if (rc == VERR_ALREADY_EXISTS)
    241264    {
     
    245268           installation directory.) */
    246269        RemoveExtPackDir(szExtPackUnInstDir, false /*fTemporary*/);
    247         rc = RTDirRename(pszExtPackDir, szExtPackUnInstDir, RTPATHRENAME_FLAGS_NO_REPLACE);
     270        rc = CommonDirRenameWrapper(pszExtPackDir, szExtPackUnInstDir, RTPATHRENAME_FLAGS_NO_REPLACE);
    248271    }
    249272    if (RT_FAILURE(rc))
     
    752775    if (rcExit == RTEXITCODE_SUCCESS)
    753776    {
    754         rc = RTDirRename(szTmpPath, szFinalPath, RTPATHRENAME_FLAGS_NO_REPLACE);
     777        rc = CommonDirRenameWrapper(szTmpPath, szFinalPath, RTPATHRENAME_FLAGS_NO_REPLACE);
    755778        if (   RT_FAILURE(rc)
    756779            && fReplace
     
    760783            rcExit = CommonUninstallWorker(szFinalPath);
    761784            if (rcExit == RTEXITCODE_SUCCESS)
    762                 rc = RTDirRename(szTmpPath, szFinalPath, RTPATHRENAME_FLAGS_NO_REPLACE);
     785                rc = CommonDirRenameWrapper(szTmpPath, szFinalPath, RTPATHRENAME_FLAGS_NO_REPLACE);
    763786        }
    764787        if (RT_SUCCESS(rc))
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