VirtualBox

Changeset 55556 in vbox for trunk/src


Ignore:
Timestamp:
Apr 30, 2015 2:27:39 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99923
Message:

DnD: Rollback handling, bugfixes, cleanup.

Location:
trunk/src/VBox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp

    r55549 r55556  
    13181318
    13191319    uint32_t cbBuf = _64K; /** @todo Make this configurable? */
    1320     void *pvBuf = RTMemAlloc(cbBuf);
     1320    void *pvBuf = RTMemAlloc(cbBuf); /** @todo Make this buffer part of PVBGLR3GUESTDNDCMDCTX? */
    13211321    if (!pvBuf)
    13221322        return VERR_NO_MEMORY;
    13231323
    13241324    RTCString strPath = obj.GetDestPath();
    1325     LogFlowFunc(("strFile=%s (%zu), fMode=0x%x\n", strPath.c_str(), strPath.length(), obj.GetMode()));
    13261325
    13271326    int rc = obj.Open(DnDURIObject::Source, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     
    13321331    }
    13331332
    1334     LogFlowFunc(("cbSize=%RU64, uProtocol=%RU32, uClientID=%RU32\n", obj.GetSize(), pCtx->uProtocol, pCtx->uClientID));
     1333    LogFlowFunc(("strFile=%s (%zu), cbSize=%RU64, fMode=0x%x\n", strPath.c_str(), strPath.length(), obj.GetSize(), obj.GetMode()));
     1334    LogFlowFunc(("uProtocol=%RU32, uClientID=%RU32\n", pCtx->uProtocol, pCtx->uClientID));
    13351335
    13361336    if (pCtx->uProtocol >= 2) /* Protocol version 2 and up sends a file header first. */
     
    14311431    }
    14321432
     1433    obj.Close();
     1434
    14331435    RTMemFree(pvBuf);
    14341436
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDURIList.cpp

    r55512 r55556  
    8282    m_cbTotal += cbSize;
    8383#ifdef DEBUG_andy
    84     LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cbTotal=%zu\n",
    85                  pcszPath, &pcszPath[cbBaseLen], objInfo.Attr.fMode, cbSize, m_cbTotal));
    86 #endif
    87 
    88     PRTDIR hDir;
     84    LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cTotal=%RU32, cbTotal=%zu\n",
     85                 pcszPath, &pcszPath[cbBaseLen], objInfo.Attr.fMode, cbSize, m_cTotal, m_cbTotal));
     86#endif
     87
    8988    /* We have to try to open even symlinks, cause they could
    9089     * be symlinks to directories. */
     90    PRTDIR hDir;
    9191    rc = RTDirOpen(&hDir, pcszPath);
     92
    9293    /* The following error happens when this was a symlink
    93      * to an file or a regular file. */
     94     * to a file or a regular file. */
    9495    if (   rc == VERR_PATH_NOT_FOUND
    9596        || rc == VERR_NOT_A_DIRECTORY)
     
    150151                                                      pszNewFile, &pszNewFile[cbBaseLen],
    151152                                                      objInfo1.Attr.fMode, cbSize));
     153                        m_cTotal++;
    152154                        m_cbTotal += cbSize;
     155#ifdef DEBUG_andy
     156                        LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cTotal=%RU32, cbTotal=%zu\n",
     157                                     pszNewFile, &pszNewFile[cbBaseLen], objInfo1.Attr.fMode, cbSize, m_cTotal, m_cbTotal));
     158#endif
    153159                    }
    154160                    else /* Handle symlink directories. */
    155161                        rc = appendPathRecursive(pszNewFile, cbBaseLen, fFlags);
    156 #ifdef DEBUG_andy
    157                     LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cbTotal=%zu\n",
    158                                  pszNewFile, &pszNewFile[cbBaseLen], objInfo1.Attr.fMode, cbSize, m_cbTotal));
    159 #endif
     162
    160163                    RTStrFree(pszNewFile);
    161164                }
     
    166169
    167170            default:
     171                /* Just ignore the rest. */
    168172                break;
    169173        }
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp

    r55549 r55556  
    3737DnDURIObject::DnDURIObject(void)
    3838    : m_Type(Unknown)
    39     , m_fMode(0)
     39    , m_fCreationMode(0)
    4040    , m_cbSize(0)
    4141    , m_cbProcessed(0)
     
    5151    , m_strSrcPath(strSrcPath)
    5252    , m_strTgtPath(strDstPath)
    53     , m_fMode(fMode)
     53    , m_fCreationMode(fMode)
    5454    , m_cbSize(cbSize)
    5555    , m_cbProcessed(0)
     
    199199                        rc = RTFileGetSize(u.m_hFile, &m_cbSize);
    200200                    if (RT_SUCCESS(rc))
     201                    {
     202                        LogFlowFunc(("cbSize=%RU64, fMode=%RU32\n", m_cbSize, m_fCreationMode));
    201203                        m_cbProcessed = 0;
     204                    }
    202205                }
    203206                else
     
    345348    Close();
    346349
    347     m_Type        = Unknown;
    348     m_strSrcPath  = "";
    349     m_strTgtPath  = "";
    350     m_fMode      = 0;
    351     m_cbSize      = 0;
    352     m_cbProcessed = 0;
     350    m_Type          = Unknown;
     351    m_strSrcPath    = "";
     352    m_strTgtPath    = "";
     353    m_fCreationMode = 0;
     354    m_cbSize        = 0;
     355    m_cbProcessed   = 0;
    353356}
    354357
  • trunk/src/VBox/Main/include/GuestDnDPrivate.h

    r55549 r55556  
    2020#define ____H_GUESTDNDPRIVATE
    2121
     22#include <iprt/dir.h>
     23#include <iprt/file.h>
     24
    2225#include "VBox/hgcmsvc.h" /* For PVBOXHGCMSVCPARM. */
    2326#include "VBox/GuestHost/DragAndDrop.h"
     
    6669typedef struct GuestDnDData
    6770{
     71    GuestDnDData(void)
     72        : cbToProcess(0)
     73        , cbProcessed(0) { }
     74
     75    void Reset(void)
     76    {
     77        vecData.clear();
     78        cbToProcess = 0;
     79        cbProcessed = 0;
     80    }
     81
    6882    /** Array (vector) of guest DnD data. This might be an URI list, according
    6983     *  to the format being set. */
     
    7387    /** Overall size (in bytes) of processed file data. */
    7488    uint64_t                  cbProcessed;
     89
    7590} GuestDnDData;
     91
     92/**
     93 * Structure for keeping around URI (list) data.
     94 */
     95typedef struct GuestDnDURIData
     96{
     97    GuestDnDURIData(void)
     98        : pvScratchBuf(NULL)
     99        , cbScratchBuf(0) { }
     100
     101    virtual ~GuestDnDURIData(void)
     102    {
     103        Reset();
     104    }
     105
     106    void Reset(void)
     107    {
     108        strDropDir = "";
     109        lstURI.Clear();
     110        lstDirs.clear();
     111        lstFiles.clear();
     112        if (pvScratchBuf)
     113        {
     114            RTMemFree(pvScratchBuf);
     115            pvScratchBuf = NULL;
     116        }
     117        cbScratchBuf = 0;
     118    }
     119
     120    int Rollback(void)
     121    {
     122        if (strDropDir.isEmpty())
     123            return VINF_SUCCESS;
     124
     125        int rc = VINF_SUCCESS;
     126        int rc2;
     127
     128        /* Rollback by removing any stuff created.
     129         * Note: Only remove empty directories, never ever delete
     130         *       anything recursive here! Steam (tm) knows best ... :-) */
     131        for (size_t i = 0; i < lstFiles.size(); i++)
     132        {
     133            rc2 = RTFileDelete(lstFiles.at(i).c_str());
     134            if (RT_SUCCESS(rc))
     135                rc = rc2;
     136        }
     137
     138        for (size_t i = 0; i < lstDirs.size(); i++)
     139        {
     140            rc2 = RTDirRemove(lstDirs.at(i).c_str());
     141            if (RT_SUCCESS(rc))
     142                rc = rc2;
     143        }
     144
     145        rc2 = RTDirRemove(strDropDir.c_str());
     146        if (RT_SUCCESS(rc))
     147            rc = rc2;
     148
     149        return rc;
     150    }
     151
     152    /** Temporary drop directory on the host where to
     153     *  put the files sent from the guest. */
     154    com::Utf8Str                    strDropDir;
     155    /** (Non-recursive) List of root URI objects to receive. */
     156    DnDURIList                      lstURI;
     157    /** Current object to receive. */
     158    DnDURIObject                    objURI;
     159    /** List for holding created directories in the case of a rollback. */
     160    RTCList<RTCString>              lstDirs;
     161    /** List for holding created files in the case of a rollback. */
     162    RTCList<RTCString>              lstFiles;
     163    /** Pointer to an optional scratch buffer to use for
     164     *  doing the actual chunk transfers. */
     165    void                           *pvScratchBuf;
     166    /** Size (in bytes) of scratch buffer. */
     167    size_t                          cbScratchBuf;
     168
     169} GuestDnDURIData;
    76170
    77171/**
     
    94188     *  This can be arbitrary data or an URI list. */
    95189    GuestDnDData                        mData;
     190    /** URI data structure. */
     191    GuestDnDURIData                     mURI;
    96192    /** Callback event to use. */
    97193    GuestDnDCallbackEvent               mCallback;
    98     /** Struct for keeping data required for URI list processing. */
    99     struct
    100     {
    101         /** List of all URI objects to send. */
    102         DnDURIList                      lstURI;
    103         /** Pointer to scratch buffer to use for
    104          *  doing the actual chunk transfers. */
    105         void                           *pvScratchBuf;
    106         /** Size (in bytes) of scratch buffer. */
    107         size_t                          cbScratchBuf;
    108     } mURI;
    109194
    110195} SENDDATACTX, *PSENDDATACTX;
     
    131216     *  This can be arbitrary data or an URI list. */
    132217    GuestDnDData                        mData;
     218    /** URI data structure. */
     219    GuestDnDURIData                     mURI;
    133220    /** Callback event to use. */
    134221    GuestDnDCallbackEvent               mCallback;
    135     /** Struct for keeping data required for URI list processing. */
    136     struct
    137     {
    138         /** Temporary drop directory on the host where to
    139          *  put the files sent from the guest. */
    140         com::Utf8Str                    strDropDir;
    141         /** (Non-recursive) List of root URI objects to receive. */
    142         DnDURIList                      lstURI;
    143         /** Current object to receive. */
    144         DnDURIObject                    objURI;
    145         /** List for holding created directories in the case of a rollback. */
    146         RTCList<RTCString>              lstDirs;
    147         /** List for holding created files in the case of a rollback. */
    148         RTCList<RTCString>              lstFiles;
    149 
    150     } mURI;
    151222
    152223} RECVDATACTX, *PRECVDATACTX;
  • trunk/src/VBox/Main/src-client/GuestDnDPrivate.cpp

    r55549 r55556  
    317317                 uStatus, uPercentage, rcOp));
    318318
    319     int vrc = VINF_SUCCESS;
     319    int rc = VINF_SUCCESS;
    320320    if (!m_progress.isNull())
    321321    {
     
    383383    }
    384384
    385     LogFlowFuncLeaveRC(vrc);
    386     return vrc;
     385    LogFlowFuncLeaveRC(rc);
     386    return rc;
    387387}
    388388
  • trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp

    r55549 r55556  
    593593        if (RT_SUCCESS(rc))
    594594        {
    595             /** @todo Unescpae path before printing. */
    596             LogRel2(("DnD: Transferring guest file to host: %s\n", pCtx->mURI.objURI.GetDestPath().c_str()));
    597 
    598595            /* Note: Protocol v1 does not send any file sizes, so always 0. */
    599596            if (mDataBase.mProtocolVersion >= 2)
    600597                rc = pCtx->mURI.objURI.SetSize(cbSize);
     598
     599            /** @todo Unescpae path before printing. */
     600            LogRel2(("DnD: Transferring guest file to host: %s (%RU64 bytes, mode 0x%x)\n",
     601                     pCtx->mURI.objURI.GetDestPath().c_str(), pCtx->mURI.objURI.GetSize(), pCtx->mURI.objURI.GetMode()));
     602
     603            /** @todo Set progress object title to current file being transferred? */
    601604
    602605            if (!cbSize) /* 0-byte file? Close again. */
     
    737740     * Reset any old data.
    738741     */
    739     pCtx->mData.vecData.clear();
    740     pCtx->mData.cbToProcess = 0;
    741     pCtx->mData.cbProcessed = 0;
    742 
    743     pResp->reset();
    744     pResp->resetProgress(m_pGuest);
     742    pCtx->mData.Reset();
     743    pCtx->mURI.Reset();
    745744
    746745    /* Set the format we are going to retrieve to have it around
    747746     * when retrieving the data later. */
     747    pResp->reset();
    748748    pResp->setFormat(pCtx->mFormat);
    749749
     
    876876        return VERR_INVALID_POINTER;
    877877
    878 #define REGISTER_CALLBACK(x) \
     878#define REGISTER_CALLBACK(x)                                    \
    879879    rc = pResp->setCallback(x, i_receiveURIDataCallback, pCtx); \
    880     if (RT_FAILURE(rc)) \
     880    if (RT_FAILURE(rc))                                         \
    881881        return rc;
    882882
    883 #define UNREGISTER_CALLBACK(x) \
    884     rc = pResp->setCallback(x, NULL); \
    885     AssertRC(rc);
     883#define UNREGISTER_CALLBACK(x)                                  \
     884    {                                                           \
     885        int rc2 = pResp->setCallback(x, NULL);                  \
     886        AssertRC(rc2);                                          \
     887    }
    886888
    887889    /*
     
    927929            rc = pCtx->mCallback.Wait(msTimeout);
    928930            LogFlowFunc(("URI callback done, rc=%Rrc\n", rc));
     931            if (RT_SUCCESS(rc))
     932            {
     933                rc = pCtx->mCallback.Result();
     934                LogFlowFunc(("Callback result is %Rrc\n", rc));
     935            }
    929936        }
    930937
     
    946953    if (RT_FAILURE(rc))
    947954    {
    948         LogFlowFunc(("Rolling back ...\n"));
    949 
    950         /* Rollback by removing any stuff created. */
    951         for (size_t i = 0; i < pCtx->mURI.lstFiles.size(); ++i)
    952             RTFileDelete(pCtx->mURI.lstFiles.at(i).c_str());
    953         for (size_t i = 0; i < pCtx->mURI.lstDirs.size(); ++i)
    954             RTDirRemove(pCtx->mURI.lstDirs.at(i).c_str());
    955     }
    956 
    957     /* Try removing (hopefully) empty drop directory in any case. */
    958     if (pCtx->mURI.strDropDir.isNotEmpty())
    959         RTDirRemove(pCtx->mURI.strDropDir.c_str());
     955        int rc2 = pCtx->mURI.Rollback(); /** @todo Inform user on rollback failure? */
     956        LogFlowFunc(("Rolling back ended with rc=%Rrc\n", rc2));
     957    }
    960958
    961959    LogFlowFuncLeaveRC(rc);
     
    11211119    }
    11221120
    1123     LogFlowFunc(("cbProcessed=%RU64, cbToProcess=%RU64, fNotify=%RTbool\n",
    1124                  pCtx->mData.cbProcessed, pCtx->mData.cbToProcess, fNotify));
     1121    LogFlowFunc(("cbProcessed=%RU64, cbToProcess=%RU64, fNotify=%RTbool, rc=%Rrc\n",
     1122                 pCtx->mData.cbProcessed, pCtx->mData.cbToProcess, fNotify, rc));
    11251123
    11261124    if (fNotify)
  • trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp

    r55549 r55556  
    737737                LogRel2(("DnD: Transferring host file to guest: %s (%RU64 bytes, mode 0x%x)\n",
    738738                         strPathSrc.c_str(), aFile.GetSize(), aFile.GetMode()));
     739
     740                /** @todo Set progress object title to current file being transferred? */
    739741            }
    740742            else
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