VirtualBox

Changeset 35757 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Jan 28, 2011 12:51:37 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69718
Message:

Main: do not fail loading machine settings if a shared folder path is not absolute (that breaks importing OVF and machine folders from other hosts since the rules about what constitutes an absolute path differ between host OSes). Instead, issue a runtime warning if a shared folder path is not absolute or does not exist on the host when the VM is powered up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r35755 r35757  
    13841384                                         strHostPath,
    13851385                                         writable,
    1386                                          autoMount);
     1386                                         autoMount,
     1387                                         false /* fFailOnError */);
    13871388        AssertComRCReturn(rc, VERR_INTERNAL_ERROR);
    13881389
     
    28512852    CheckComArgStrNotEmptyOrNull(aHostPath);
    28522853
     2854    LogFlowThisFunc(("Entering for '%ls' -> '%ls'\n", aName, aHostPath));
     2855
    28532856    AutoCaller autoCaller(this);
    28542857    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     
    28772880    if (SUCCEEDED(rc))
    28782881        return setError(VBOX_E_FILE_ERROR,
    2879             tr("Shared folder named '%s' already exists"),
    2880             strName.c_str());
     2882                        tr("Shared folder named '%s' already exists"),
     2883                        strName.c_str());
    28812884
    28822885    pSharedFolder.createObject();
    2883     rc = pSharedFolder->init(this, strName, strHostPath, aWritable, aAutoMount);
     2886    rc = pSharedFolder->init(this,
     2887                             strName,
     2888                             strHostPath,
     2889                             aWritable,
     2890                             aAutoMount,
     2891                             true /* fFailOnError */);
    28842892    if (FAILED(rc)) return rc;
    28852893
     
    29142922    fireSharedFolderChangedEvent(mEventSource, Scope_Session);
    29152923
     2924    LogFlowThisFunc(("Leaving for '%ls' -> '%ls'\n", aName, aHostPath));
     2925
    29162926    return rc;
    29172927}
     
    29232933    AutoCaller autoCaller(this);
    29242934    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2935
     2936    LogFlowThisFunc(("Entering for '%ls'\n", aName));
    29252937
    29262938    Utf8Str strName(aName);
     
    29762988    /* notify console callbacks after the folder is removed to the list */
    29772989    fireSharedFolderChangedEvent(mEventSource, Scope_Session);
     2990
     2991    LogFlowThisFunc(("Leaving for '%ls'\n", aName));
    29782992
    29792993    return rc;
     
    61956209                 isWriteLockOnCurrentThread(), E_FAIL);
    61966210
     6211    LogFlowThisFunc(("Entering\n"));
     6212
    61976213    /* protect mpVM (if not NULL) */
    61986214    AutoVMCallerQuietWeak autoVMCaller(this);
     
    62056221                  && m_pVMMDev->isShFlActive();
    62066222
    6207     if (aGlobal)
    6208     {
    6209         /// @todo grab & process global folders when they are done
    6210     }
    6211     else
    6212     {
    6213         SharedFolderDataMap oldFolders;
    6214         if (online)
    6215             oldFolders = m_mapMachineSharedFolders;
    6216 
    6217         m_mapMachineSharedFolders.clear();
    6218 
    6219         SafeIfaceArray<ISharedFolder> folders;
    6220         rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders));
    6221         AssertComRCReturnRC(rc);
    6222 
    6223         for (size_t i = 0; i < folders.size(); ++i)
    6224         {
    6225             ComPtr<ISharedFolder> pSharedFolder = folders[i];
    6226 
    6227             Bstr bstrName;
    6228             Bstr bstrHostPath;
    6229             BOOL writable;
    6230             BOOL autoMount;
    6231 
    6232             rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam());
    6233             if (FAILED(rc)) break;
    6234             Utf8Str strName(bstrName);
    6235 
    6236             rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam());
    6237             if (FAILED(rc)) break;
    6238             Utf8Str strHostPath(bstrHostPath);
    6239 
    6240             rc = pSharedFolder->COMGETTER(Writable)(&writable);
    6241             if (FAILED(rc)) break;
    6242 
    6243             rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount);
    6244             if (FAILED(rc)) break;
    6245 
    6246             m_mapMachineSharedFolders.insert(std::make_pair(strName,
    6247                                                             SharedFolderData(strHostPath, writable, autoMount)));
    6248 
    6249             /* send changes to HGCM if the VM is running */
    6250             /// @todo umoeller report errors as runtime warnings through VMSetError
     6223    try
     6224    {
     6225        if (aGlobal)
     6226        {
     6227            /// @todo grab & process global folders when they are done
     6228        }
     6229        else
     6230        {
     6231            SharedFolderDataMap oldFolders;
     6232            if (online)
     6233                oldFolders = m_mapMachineSharedFolders;
     6234
     6235            m_mapMachineSharedFolders.clear();
     6236
     6237            SafeIfaceArray<ISharedFolder> folders;
     6238            rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders));
     6239            if (FAILED(rc)) throw rc;
     6240
     6241            for (size_t i = 0; i < folders.size(); ++i)
     6242            {
     6243                ComPtr<ISharedFolder> pSharedFolder = folders[i];
     6244
     6245                Bstr bstrName;
     6246                Bstr bstrHostPath;
     6247                BOOL writable;
     6248                BOOL autoMount;
     6249
     6250                rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam());
     6251                if (FAILED(rc)) throw rc;
     6252                Utf8Str strName(bstrName);
     6253
     6254                rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam());
     6255                if (FAILED(rc)) throw rc;
     6256                Utf8Str strHostPath(bstrHostPath);
     6257
     6258                rc = pSharedFolder->COMGETTER(Writable)(&writable);
     6259                if (FAILED(rc)) throw rc;
     6260
     6261                rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount);
     6262                if (FAILED(rc)) throw rc;
     6263
     6264                m_mapMachineSharedFolders.insert(std::make_pair(strName,
     6265                                                                SharedFolderData(strHostPath, writable, autoMount)));
     6266
     6267                /* send changes to HGCM if the VM is running */
     6268                /// @todo umoeller report errors as runtime warnings through VMSetError
     6269                if (online)
     6270                {
     6271                    SharedFolderDataMap::iterator it = oldFolders.find(strName);
     6272                    if (    it == oldFolders.end()
     6273                         || it->second.m_strHostPath != strHostPath)
     6274                    {
     6275                        /* a new machine folder is added or
     6276                         * the existing machine folder is changed */
     6277                        if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end())
     6278                            ; /* the console folder exists, nothing to do */
     6279                        else
     6280                        {
     6281                            /* remove the old machine folder (when changed)
     6282                             * or the global folder if any (when new) */
     6283                            if (    it != oldFolders.end()
     6284                                 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end()
     6285                               )
     6286                            {
     6287                                rc = removeSharedFolder(strName);
     6288                                if (FAILED(rc)) throw rc;
     6289                            }
     6290
     6291                            /* create the new machine folder */
     6292                            rc = createSharedFolder(strName,
     6293                                                    SharedFolderData(strHostPath,
     6294                                                                     writable,
     6295                                                                     autoMount));
     6296                            if (FAILED(rc)) throw rc;
     6297                        }
     6298                    }
     6299                    /* forget the processed (or identical) folder */
     6300                    if (it != oldFolders.end())
     6301                        oldFolders.erase(it);
     6302                }
     6303            }
     6304
     6305            /* process outdated (removed) folders */
    62516306            if (online)
    62526307            {
    6253                 SharedFolderDataMap::iterator it = oldFolders.find(strName);
    6254                 if (    it == oldFolders.end()
    6255                      || it->second.m_strHostPath != strHostPath)
     6308                for (SharedFolderDataMap::const_iterator it = oldFolders.begin();
     6309                     it != oldFolders.end(); ++ it)
    62566310                {
    6257                     /* a new machine folder is added or
    6258                      * the existing machine folder is changed */
    6259                     if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end())
     6311                    if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end())
    62606312                        ; /* the console folder exists, nothing to do */
    62616313                    else
    62626314                    {
    6263                         /* remove the old machine folder (when changed)
    6264                          * or the global folder if any (when new) */
    6265                         if (    it != oldFolders.end()
    6266                              || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end()
    6267                            )
    6268                             rc = removeSharedFolder(strName);
    6269                         /* create the new machine folder */
    6270                         rc = createSharedFolder(strName,
    6271                                                 SharedFolderData(strHostPath,
    6272                                                                  writable,
    6273                                                                  autoMount));
     6315                        /* remove the outdated machine folder */
     6316                        rc = removeSharedFolder(it->first);
     6317                        if (FAILED(rc)) throw rc;
     6318
     6319                        /* create the global folder if there is any */
     6320                        SharedFolderDataMap::const_iterator git =
     6321                            m_mapGlobalSharedFolders.find(it->first);
     6322                        if (git != m_mapGlobalSharedFolders.end())
     6323                        {
     6324                            rc = createSharedFolder(git->first, git->second);
     6325                            if (FAILED(rc)) throw rc;
     6326                        }
    62746327                    }
    62756328                }
    6276                 /* forget the processed (or identical) folder */
    6277                 if (it != oldFolders.end())
    6278                     oldFolders.erase(it);
    6279 
    6280                 rc = S_OK;
    62816329            }
    62826330        }
    6283 
    6284         AssertComRCReturnRC(rc);
    6285 
    6286         /* process outdated (removed) folders */
    6287         /// @todo report errors as runtime warnings through VMSetError
     6331    }
     6332    catch (HRESULT rc2)
     6333    {
    62886334        if (online)
    6289         {
    6290             for (SharedFolderDataMap::const_iterator it = oldFolders.begin();
    6291                  it != oldFolders.end(); ++ it)
    6292             {
    6293                 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end())
    6294                     ; /* the console folder exists, nothing to do */
    6295                 else
    6296                 {
    6297                     /* remove the outdated machine folder */
    6298                     rc = removeSharedFolder(it->first);
    6299                     /* create the global folder if there is any */
    6300                     SharedFolderDataMap::const_iterator git =
    6301                         m_mapGlobalSharedFolders.find(it->first);
    6302                     if (git != m_mapGlobalSharedFolders.end())
    6303                         rc = createSharedFolder(git->first, git->second);
    6304                 }
    6305             }
    6306 
    6307             rc = S_OK;
    6308         }
    6309     }
     6335            setVMRuntimeErrorCallbackF(mpVM, this, 0, "BrokenSharedFolder",
     6336                                       N_("Broken shared folder!"));
     6337    }
     6338
     6339    LogFlowThisFunc(("Leaving\n"));
    63106340
    63116341    return rc;
     
    63646394
    63656395    Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str()));
     6396
     6397    // check whether the path is valid and exists
     6398    /* Check whether the path is full (absolute) */
     6399    char hostPathFull[RTPATH_MAX];
     6400    int vrc = RTPathAbsEx(NULL,
     6401                          aData.m_strHostPath.c_str(),
     6402                          hostPathFull,
     6403                          sizeof(hostPathFull));
     6404    if (RT_FAILURE(vrc))
     6405        return setError(E_INVALIDARG,
     6406                        tr("Invalid shared folder path: '%s' (%Rrc)"),
     6407                        aData.m_strHostPath.c_str(), vrc);
     6408
     6409    if (RTPathCompare(aData.m_strHostPath.c_str(), hostPathFull) != 0)
     6410        return setError(E_INVALIDARG,
     6411                        tr("Shared folder path '%s' is not absolute"),
     6412                        aData.m_strHostPath.c_str());
     6413    if (!RTPathExists(hostPathFull))
     6414        return setError(E_INVALIDARG,
     6415                        tr("Shared folder path '%s' does not exist on the host"),
     6416                        aData.m_strHostPath.c_str());
     6417
     6418    // now that we know the path is good, give it to HGCM
    63666419
    63676420    Bstr bstrName(strName);
     
    64116464    parms[3].u.uint32 = aData.m_fAutoMount;
    64126465
    6413     int vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",
    6414                                       SHFL_FN_ADD_MAPPING,
    6415                                       SHFL_CPARMS_ADD_MAPPING2, &parms[0]);
     6466    vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",
     6467                                  SHFL_FN_ADD_MAPPING,
     6468                                  SHFL_CPARMS_ADD_MAPPING2, &parms[0]);
    64166469    RTMemFree(pFolderName);
    64176470    RTMemFree(pMapName);
     
    78307883                    {
    78317884                        const SharedFolderData &d = it->second;
    7832                         rc = pConsole->createSharedFolder(it->first,
    7833                                                           d);
    7834                         if (FAILED(rc)) break;
     7885                        rc = pConsole->createSharedFolder(it->first, d);
     7886                        if (FAILED(rc))
     7887                        {
     7888                            ErrorInfoKeeper eik;
     7889                            setVMRuntimeErrorCallbackF(pVM, pConsole, 0, "BrokenSharedFolder",
     7890                                                       N_("The shared folder '%s' could not be set up: %ls.\n"
     7891                                                          "The shared folder setup will not be complete. It is recommended to power down the virtual machine and "
     7892                                                          "fix the shared folder settings while the machine is not running."),
     7893                                                       it->first.c_str(), eik.getText().raw());
     7894                            break;
     7895                        }
    78357896                    }
    7836                     if (FAILED(rc)) break;
     7897                    if (FAILED(rc))
     7898                        rc = S_OK;          // do not fail with broken shared folders
    78377899
    78387900                    /* enter the lock again */
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