Changeset 78761 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- May 26, 2019 4:31:12 AM (6 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r78632 r78761 5458 5458 DeleteConfigTask *pTask = new DeleteConfigTask(this, pProgress, "DeleteVM", llMediums, llFilesToDelete); 5459 5459 rc = pTask->createThread(); 5460 pTask = NULL; 5460 5461 if (FAILED(rc)) 5461 5462 return rc; … … 7154 7155 LogFlowThisFuncEnter(); 7155 7156 7156 ComObjPtr<Progress> progress; 7157 7158 progress.createObject(); 7159 7160 HRESULT rc = S_OK; 7161 Utf8Str targetPath = aTargetPath; 7162 Utf8Str type = aType; 7163 7164 /* Initialize our worker task */ 7165 MachineMoveVM* task = NULL; 7166 try 7167 { 7168 task = new MachineMoveVM(this, targetPath, type, progress); 7169 } 7170 catch(...) 7171 { 7172 delete task; 7173 return rc; 7174 } 7175 7176 /* 7177 * task pointer will be owned by the ThreadTask class. 7178 * There is no need to call operator "delete" in the end. 7179 */ 7180 rc = task->init(); 7181 if (SUCCEEDED(rc)) 7182 { 7183 rc = task->createThread(); 7184 if (FAILED(rc)) 7185 { 7186 setError(rc, tr("Could not run the thread for the task MachineMoveVM")); 7187 } 7188 7189 /* Return progress to the caller */ 7190 progress.queryInterfaceTo(aProgress.asOutParam()); 7157 ComObjPtr<Progress> ptrProgress; 7158 HRESULT hrc = ptrProgress.createObject(); 7159 if (SUCCEEDED(hrc)) 7160 { 7161 /* Initialize our worker task */ 7162 MachineMoveVM *pTask = NULL; 7163 try 7164 { 7165 pTask = new MachineMoveVM(this, aTargetPath, aType, ptrProgress); 7166 } 7167 catch (std::bad_alloc &) 7168 { 7169 return E_OUTOFMEMORY; 7170 } 7171 /** @todo r=bird: Turned out the init() function throws stuff of type int 7172 * without telling anyone. Probably unintentionally. The catching 7173 * here is only temporary until someone can be bothered to fix it 7174 * properly. */ 7175 try 7176 { 7177 hrc = pTask->init(); 7178 } 7179 catch (...) 7180 { 7181 hrc = setError(E_FAIL, tr("Unknown exception thrown by MachineMoveVM::init")); 7182 } 7183 if (SUCCEEDED(hrc)) 7184 { 7185 hrc = pTask->createThread(); 7186 pTask = NULL; /* Consumed by createThread(). */ 7187 if (SUCCEEDED(hrc)) 7188 ptrProgress.queryInterfaceTo(aProgress.asOutParam()); 7189 else 7190 setError(hrc, tr("Failed to create a worker thread for the MachineMoveVM task")); 7191 } 7192 else 7193 delete pTask; 7191 7194 } 7192 7195 7193 7196 LogFlowThisFuncLeave(); 7194 return rc;7197 return hrc; 7195 7198 7196 7199 } -
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r78404 r78761 153 153 { 154 154 size_t len = m_targetPath.length() + 2; 155 if (len >=RTPATH_MAX) 156 { 155 if (len >= RTPATH_MAX) 156 { 157 /** @todo r=bird: Why the leading space in errorDesc? */ 158 /** @todo "The destination path exceeds the maximum length" should 159 * suffice here, I think. */ 160 /** @todo r=bird: missing tr(). */ 161 /** @todo r=bird: Actually, why bother with these error strings here? Nobody 162 * will ever see them, given that the caller deletes the task when 163 * init() fails. */ 157 164 Utf8Str errorDesc(" The destination path isn't correct. The length of path exceeded the maximum value."); 158 165 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 166 /** @todo r=bird: What on earth is this? It will cause the caller to leak the 167 * task structure, unless it's catching exception (which it wasn't, but 168 * I made it is now). I sure hope this wasn't intentional... */ 159 169 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 160 170 } 161 171 172 /** @todo r=bird: I need to add a Utf8Str method or iprt/cxx/path.h thingy 173 * for doing this. We need this often and code like this doesn't 174 * need to be repeated and re-optimized in each instance... */ 162 175 char* path = new char [len]; 163 176 RTStrCopy(path, len, m_targetPath.c_str()); … … 178 191 try 179 192 { 180 Utf8Str info;181 int vrc = 0;182 183 193 RTFOFF cbTotal = 0; 184 194 RTFOFF cbFree = 0; … … 186 196 uint32_t cbSector = 0; 187 197 188 vrc = RTFsQuerySizes(strTargetFolder.c_str(), &cbTotal, &cbFree, &cbBlock, &cbSector);198 int vrc = RTFsQuerySizes(strTargetFolder.c_str(), &cbTotal, &cbFree, &cbBlock, &cbSector); 189 199 if (FAILED(vrc)) 190 200 { 201 /** @todo r=bird: What's this RTPrint doing here?!? */ 191 202 RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str()); 192 203 Utf8StrFmt errorDesc("Unable to move machine. Can't get the destination storage size (%s)", … … 201 212 vrc = RTDirOpen(&hDir, strTargetFolder.c_str()); 202 213 if (FAILED(vrc)) 203 throw rc = vrc; 214 throw rc = vrc; /** @todo r=bird: RTDirOpen returns a VBox status code. That is _not_ the same as a COM HRESULT! */ 204 215 else 205 216 { … … 213 224 errorsList.push_back(ErrorInfoItem(HRESULT(vrc), errorDesc.c_str())); 214 225 rc = m_pMachine->setErrorBoth(VBOX_E_FILE_ERROR, vrc, m_pMachine->tr(errorDesc.c_str())); 215 } 216 217 RTFileClose(hFile); 226 /** @todo r=bird: What happens to this error and 'rc'? Should it be ignored? */ 227 } 228 229 RTFileClose(hFile); /** @todo r=bird: Whey close if opening fail? */ 218 230 RTFileDelete(strTempFile.c_str()); 219 231 RTDirClose(hDir); 220 232 } 221 233 222 long long totalFreeSpace = cbFree; 223 long long totalSpace = cbTotal; 224 info = Utf8StrFmt("blocks: total %lld, free %u ", cbTotal, cbFree); 234 /** @todo r=bird: Why the need for 'info' here? LogRelFunc can do the exact 235 * same thing without touching the heap. I don't get what this is 236 * about... There is also excessive log duplication here as well as 237 * seemingly unnecessary trailing whitespace. */ 238 Utf8Str info = Utf8StrFmt("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree); 225 239 LogRelFunc(("%s \n", info.c_str())); 226 LogRelFunc(("total space (Kb) %lld (Mb) %lld (Gb) %lld\n", 227 totalSpace/1024, totalSpace/(1024*1024), totalSpace/(1024*1024*1024))); 228 LogRelFunc(("total free space (Kb) %lld (Mb) %lld (Gb) %lld\n", 229 totalFreeSpace/1024, totalFreeSpace/(1024*1024), totalFreeSpace/(1024*1024*1024))); 240 LogRelFunc(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G)); 241 LogRelFunc(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G)); 230 242 231 243 RTFSPROPERTIES properties; … … 245 257 Utf8Str strSettingsFilePath; 246 258 Bstr bstr_settingsFilePath; 247 m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); 259 m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); /** @todo r=bird: check the status code. */ 248 260 strSettingsFilePath = bstr_settingsFilePath; 249 261 strSettingsFilePath.stripFilename(); … … 277 289 rc = m_pMachine->COMGETTER(State)(&machineState); 278 290 if (FAILED(rc)) throw rc; 279 elseif (machineState == MachineState_Saved)291 if (machineState == MachineState_Saved) 280 292 { 281 293 m_pMachine->COMGETTER(StateFilePath)(bstr_stateFilePath.asOutParam()); … … 340 352 341 353 /* The lists llMedias and llSaveStateFiles are filled in the queryMediasForAllStates() */ 342 queryMediasForAllStates(machineList); 354 queryMediasForAllStates(machineList); /** @todo r=bird: As a rule status codes needs checking every time. */ 343 355 344 356 { … … 429 441 { 430 442 neededFreeSpace += totalLogSize; 431 if ( totalFreeSpace - neededFreeSpace <= 1024*1024)443 if (cbFree - neededFreeSpace <= _1M) 432 444 { 433 445 throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location … … 435 447 436 448 fileList_t filesList; 437 getFilesList(strFolder, filesList); 449 getFilesList(strFolder, filesList); /** @todo r=bird: return code check */ 438 450 cit_t it = filesList.m_list.begin(); 439 while (it != filesList.m_list.end())451 while (it != filesList.m_list.end()) 440 452 { 441 453 Utf8Str strFile = it->first.c_str(); … … 467 479 LogRelFunc(("Total space needed is %lld bytes\n", neededFreeSpace)); 468 480 /* Check a target location on enough room */ 469 if (totalFreeSpace - neededFreeSpace <= 1024*1024) 470 { 471 LogRelFunc(("but free space on destination is %lld\n", totalFreeSpace)); 481 if (cbFree - neededFreeSpace <= _1M) 482 { 483 LogRelFunc(("but free space on destination is %RTfoff\n", cbFree)); 484 /** @todo r=bird: You're throwing a VBox status code here, but only catching 485 * HRESULT. So, this will go to the caller or someone else up the 486 * stack, which is unacceptable throw behaviour. */ 472 487 throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location 473 488 } 474 489 475 490 /* Add step for .vbox machine setting file */ 476 { 491 { /** @todo what's the scoping for? */ 477 492 ++uCount; 478 493 uTotalWeight += 1; … … 488 503 { 489 504 rc = m_pProgress->init(m_pMachine->i_getVirtualBox(), 490 static_cast<IMachine*>(m_pMachine) /* aInitiator */,491 Bstr(m_pMachine->tr("Moving Machine")).raw(),492 true /* fCancellable */,493 uCount,494 uTotalWeight,495 Bstr(m_pMachine->tr("Initialize Moving")).raw(),496 1);505 static_cast<IMachine*>(m_pMachine) /* aInitiator */, 506 Utf8Str(m_pMachine->tr("Moving Machine")), 507 true /* fCancellable */, 508 uCount, 509 uTotalWeight, 510 Utf8Str(m_pMachine->tr("Initialize Moving")), 511 1); 497 512 if (FAILED(rc)) 498 513 { … … 510 525 catch(HRESULT hrc) 511 526 { 527 /** @todo r=bird: Seriously, why throw any error when you can just return 528 * them. This is just copying the thrown message and passing it onto 529 * the return statemnt a few lines later. (The log statemnt doesn't 530 * really count as it doesn't log the status.) */ 512 531 rc = hrc; 513 532 }
Note:
See TracChangeset
for help on using the changeset viewer.