- Timestamp:
- Feb 28, 2019 8:44:11 AM (6 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestSessionImplTasks.h
r77068 r77495 188 188 /** @name Directory handling primitives. 189 189 * @{ */ 190 int directoryCreate(const com::Utf8Str &strPath, DirectoryCreateFlag_T enmDirecotryCreateFlags, uint32_t uMode, 191 bool fFollowSymlinks); 190 int directoryCreateOnGuest(const com::Utf8Str &strPath, 191 DirectoryCreateFlag_T enmDirectoryCreateFlags, uint32_t uMode, 192 bool fFollowSymlinks, bool fCanExist); 193 int directoryCreateOnHost(const com::Utf8Str &strPath, uint32_t fCreate, uint32_t uMode, bool fCanExist); 192 194 /** @} */ 193 195 -
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r77038 r77495 223 223 * @param uMode Directory mode to use for creation. 224 224 * @param fFollowSymlinks Whether to follow symlinks on the guest or not. 225 * @param fCanExist Whether the directory to create is allowed to exist already. 225 226 */ 226 int GuestSessionTask::directoryCreate(const com::Utf8Str &strPath, 227 DirectoryCreateFlag_T enmDirectoryCreateFlags, uint32_t uMode, bool fFollowSymlinks) 228 { 229 LogFlowFunc(("strPath=%s, fFlags=0x%x, uMode=%RU32, fFollowSymlinks=%RTbool\n", 230 strPath.c_str(), enmDirectoryCreateFlags, uMode, fFollowSymlinks)); 227 int GuestSessionTask::directoryCreateOnGuest(const com::Utf8Str &strPath, 228 DirectoryCreateFlag_T enmDirectoryCreateFlags, uint32_t uMode, 229 bool fFollowSymlinks, bool fCanExist) 230 { 231 LogFlowFunc(("strPath=%s, enmDirectoryCreateFlags=0x%x, uMode=%RU32, fFollowSymlinks=%RTbool, fCanExist=%RTbool\n", 232 strPath.c_str(), enmDirectoryCreateFlags, uMode, fFollowSymlinks, fCanExist)); 231 233 232 234 GuestFsObjData objData; int rcGuest; … … 234 236 if (RT_SUCCESS(rc)) 235 237 { 236 return VERR_ALREADY_EXISTS; 238 if (!fCanExist) 239 { 240 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 241 Utf8StrFmt(GuestSession::tr("Guest directory \"%s\" already exists"), strPath.c_str())); 242 return VERR_ALREADY_EXISTS; 243 } 237 244 } 238 245 else … … 268 275 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 269 276 Utf8StrFmt(GuestSession::tr("Error creating directory on the guest: %Rrc"), strPath.c_str(), rc)); 277 } 278 279 LogFlowFuncLeaveRC(rc); 280 return rc; 281 } 282 283 /** 284 * Creates a directory on the host. 285 * 286 * @return VBox status code. VERR_ALREADY_EXISTS if directory on the guest already exists. 287 * @param strPath Absolute path to directory on the host (host style path) to create. 288 * @param fCreate Directory creation flags. 289 * @param uMode Directory mode to use for creation. 290 * @param fCanExist Whether the directory to create is allowed to exist already. 291 */ 292 int GuestSessionTask::directoryCreateOnHost(const com::Utf8Str &strPath, uint32_t fCreate, uint32_t uMode, bool fCanExist) 293 { 294 LogFlowFunc(("strPath=%s, fCreate=0x%x, uMode=%RU32, fCanExist=%RTbool\n", strPath.c_str(), fCreate, uMode, fCanExist)); 295 296 int rc = RTDirCreate(strPath.c_str(), uMode, fCreate); 297 if (RT_FAILURE(rc)) 298 { 299 if (rc == VERR_ALREADY_EXISTS) 300 { 301 if (!fCanExist) 302 { 303 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 304 Utf8StrFmt(GuestSession::tr("Host directory \"%s\" already exists"), strPath.c_str())); 305 } 306 else 307 rc = VINF_SUCCESS; 308 } 309 else 310 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 311 Utf8StrFmt(GuestSession::tr("Could not create host directory \"%s\": %Rrc"), 312 strPath.c_str(), rc)); 270 313 } 271 314 … … 1510 1553 1511 1554 const bool fCopyIntoExisting = pList->mSourceSpec.Type.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting; 1555 const bool fFollowSymlinks = true; /** @todo */ 1512 1556 const uint32_t fDirMode = 0700; /** @todo Play safe by default; implement ACLs. */ 1557 uint32_t fDirCreate = 0; 1558 1559 if (!fFollowSymlinks) 1560 fDirCreate |= RTDIRCREATE_FLAGS_NO_SYMLINKS; 1513 1561 1514 1562 LogFlowFunc(("List: srcRootAbs=%s, dstRootAbs=%s\n", pList->mSrcRootAbs.c_str(), pList->mDstRootAbs.c_str())); … … 1517 1565 if (pList->mSourceSpec.enmType == FsObjType_Directory) 1518 1566 { 1519 rc = RTDirCreate(pList->mDstRootAbs.c_str(), fDirMode, 0 /* fCreate */); 1520 if ( rc == VWRN_ALREADY_EXISTS 1521 && !fCopyIntoExisting) 1522 { 1523 break; 1524 } 1567 rc = directoryCreateOnHost(pList->mDstRootAbs.c_str(), fDirMode, fDirCreate, fCopyIntoExisting); 1568 if (RT_FAILURE(rc)) 1569 break; 1525 1570 } 1526 1571 … … 1550 1595 if (!pList->mSourceSpec.fDryRun) 1551 1596 { 1552 rc = RTDirCreate(strDstAbs.c_str(), fDirMode, 0 /* fCreate */); 1553 if (rc == VERR_ALREADY_EXISTS) 1554 { 1555 if (!fCopyIntoExisting) 1556 { 1557 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 1558 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" already exists"), 1559 strDstAbs.c_str())); 1560 break; 1561 } 1562 1563 rc = VINF_SUCCESS; 1564 } 1565 1597 rc = directoryCreateOnHost(pList->mDstRootAbs.c_str(), fDirMode, fDirCreate, fCopyIntoExisting); 1566 1598 if (RT_FAILURE(rc)) 1567 1599 break; … … 1775 1807 fFollowSymlinks = pList->mSourceSpec.Type.Dir.fFollowSymlinks; 1776 1808 1777 rc = directoryCreate(pList->mDstRootAbs.c_str(), DirectoryCreateFlag_None, fDirMode, 1778 pList->mSourceSpec.Type.Dir.fFollowSymlinks); 1779 if ( rc == VWRN_ALREADY_EXISTS 1780 && !fCopyIntoExisting) 1781 { 1782 break; 1783 } 1809 rc = directoryCreateOnGuest(pList->mDstRootAbs.c_str(), DirectoryCreateFlag_None, fDirMode, 1810 pList->mSourceSpec.Type.Dir.fFollowSymlinks, fCopyIntoExisting); 1811 if (RT_FAILURE(rc)) 1812 break; 1784 1813 } 1785 1814 else if (pList->mSourceSpec.enmType == FsObjType_File) … … 1813 1842 if (!pList->mSourceSpec.fDryRun) 1814 1843 { 1815 rc = directoryCreate(strDstAbs.c_str(), DirectoryCreateFlag_None, fDirMode, fFollowSymlinks); 1844 rc = directoryCreateOnGuest(strDstAbs.c_str(), DirectoryCreateFlag_None, fDirMode, 1845 fFollowSymlinks, fCopyIntoExisting); 1816 1846 if (RT_FAILURE(rc)) 1817 { 1818 if (rc == VERR_ALREADY_EXISTS) 1819 { 1820 if (!fCopyIntoExisting) 1821 { 1822 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 1823 Utf8StrFmt(GuestSession::tr("Destination directory '%s' already exists"), 1824 strDstAbs.c_str())); 1825 } 1826 else /* Copy into destination directory. */ 1827 rc = VINF_SUCCESS; 1828 } 1829 } 1847 break; 1830 1848 } 1831 1849 break;
Note:
See TracChangeset
for help on using the changeset viewer.