- Timestamp:
- Apr 12, 2018 12:23:29 PM (7 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestSessionImplTasks.h
r71824 r71847 116 116 * asynchronously. Optional. */ 117 117 ComObjPtr<Progress> mProgress; 118 /** The guest's path style (depending on the guest OS type set). */ 119 uint32_t mfPathStyle; 118 120 }; 119 121 … … 144 146 145 147 GuestSessionCopyTask(GuestSession *pSession) 146 : GuestSessionTask(pSession) { RT_ZERO(u); } 148 : GuestSessionTask(pSession) 149 { 150 RT_ZERO(u); 151 } 147 152 148 153 virtual ~GuestSessionCopyTask() { } … … 151 156 152 157 /** Source to copy from. */ 153 Utf8Str mSource;158 Utf8Str mSource; 154 159 /** Destination to copy to. */ 155 Utf8Str mDest;160 Utf8Str mDest; 156 161 /** Filter (wildcard-style) when copying directories. */ 157 Utf8Str mFilter;162 Utf8Str mFilter; 158 163 159 164 union -
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r71827 r71847 71 71 { 72 72 mSession = pSession; 73 74 mfPathStyle = mSession->i_getPathStyle() == PathStyle_DOS 75 ? RTPATH_STR_F_STYLE_DOS : RTPATH_STR_F_STYLE_UNIX; 73 76 } 74 77 … … 516 519 else if (RTFS_IS_DIRECTORY(dstObjInfo.Attr.fMode)) 517 520 { 518 if ( strDest.endsWith("\\") 519 || strDest.endsWith("/")) 520 { 521 /* Build the final file name with destination path (on the host). */ 522 char szDstPath[RTPATH_MAX]; 523 RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", strDest.c_str()); 524 525 RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilename(strSource.c_str())); 526 527 pszDstFile = RTStrDup(szDstPath); 528 } 529 else 530 { 531 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 532 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" already exists"), 533 strDest.c_str(), rc)); 534 rc = VERR_ALREADY_EXISTS; 535 } 521 /* Build the final file name with destination path (on the host). */ 522 char szDstPath[RTPATH_MAX]; 523 RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", strDest.c_str()); 524 525 if ( !strDest.endsWith("\\") 526 && !strDest.endsWith("/")) 527 RTPathAppend(szDstPath, sizeof(szDstPath), "/"); /* IPRT can handle / on all hosts. */ 528 529 RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilenameEx(strSource.c_str(), mfPathStyle)); 530 531 pszDstFile = RTStrDup(szDstPath); 536 532 } 537 533 else if (RTFS_IS_SYMLINK(dstObjInfo.Attr.fMode)) … … 992 988 Utf8Str strSrcCur = strSrcDir + strSrcSubDir; 993 989 994 LogFlowFunc(("Entering '%s'\n", strSrcCur.c_str())); 990 LogFlowFunc(("strSrcDir=%s, strDstDir=%s, strFilter=%s, strSubDir=%s\n", 991 strSrcDir.c_str(), strDstDir.c_str(), strFilter.c_str(), strSubDir.c_str())); 995 992 996 993 int rc; … … 1124 1121 int rc = VINF_SUCCESS; 1125 1122 1126 /* Figure out if we need to copy the entire source directory or just its contents. */1127 1123 Utf8Str strSrcDir = mSource; 1128 1124 Utf8Str strDstDir = mDest; 1125 1126 bool fDstExists = RTDirExists(strDstDir.c_str()); 1127 if (fDstExists) 1128 { 1129 if (!(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting)) 1130 { 1131 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 1132 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str())); 1133 rc = VERR_ALREADY_EXISTS; 1134 } 1135 } 1136 1137 if (RT_FAILURE(rc)) 1138 return rc; 1139 1129 1140 if ( !strSrcDir.endsWith("/") 1130 1141 && !strSrcDir.endsWith("\\")) 1131 1142 { 1132 if ( strDstDir.endsWith("/")1133 ||strDstDir.endsWith("\\"))1134 {1135 strDstDir += Utf8StrFmt("%s", RTPathFilename(strSrcDir.c_str())); 1136 }1137 } 1138 1139 /* Create the roottarget directory on the host.1143 if ( !strDstDir.endsWith("/") 1144 && !strDstDir.endsWith("\\")) 1145 strDstDir += "/"; /* IPRT can handle / on all hosts. */ 1146 1147 strDstDir += Utf8StrFmt("%s", RTPathFilenameEx(strSrcDir.c_str(), mfPathStyle)); 1148 } 1149 1150 /* Create the final target directory on the host. 1140 1151 * The target directory might already exist on the host (based on u.Dir.fCopyFlags). */ 1141 const bool fExists = RTDirExists(strDstDir.c_str()); 1142 if ( fExists 1143 && !(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting)) 1144 { 1145 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 1146 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str())); 1147 rc = VERR_ALREADY_EXISTS; 1148 } 1149 else if (!fExists) 1152 fDstExists = RTDirExists(strDstDir.c_str()); 1153 if (fDstExists) 1154 { 1155 if (!(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting)) 1156 { 1157 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 1158 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str())); 1159 rc = VERR_ALREADY_EXISTS; 1160 } 1161 } 1162 else 1150 1163 { 1151 1164 rc = RTDirCreate(strDstDir.c_str(), fDirMode, 0); … … 1168 1181 return rc; 1169 1182 } 1183 1184 LogFlowFunc(("Source: %s -> %s\n", mSource.c_str(), strSrcDir.c_str())); 1185 LogFlowFunc(("Destination: %s -> %s\n", mDest.c_str(), strDstDir.c_str())); 1170 1186 1171 1187 /* At this point the directory on the host was created and (hopefully) is ready -
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r71828 r71847 3370 3370 sDst = sScratchHst + "/"), 3371 3371 tdTestResult(fRc = True) ], 3372 # Destination is a directory ( should fail).3372 # Destination is a directory (without a trailing slash, should also work). 3373 3373 # See "cp" syntax. 3374 3374 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll', 3375 3375 sDst = sScratchHst), 3376 tdTestResult(fRc = True) ], 3377 # Destination is a non-existing directory. 3378 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll', 3379 sDst = sScratchHst + "/non-existing-directory/"), 3376 3380 tdTestResult(fRc = False) ] 3377 3381 ]); … … 3384 3388 # Copying entire directories (destination is "<sScratch>", which exists, which should fail). 3385 3389 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web', 3386 sDst = sScratchHst),3390 sDst = sScratchHst), 3387 3391 tdTestResult(fRc = False) ], 3388 # Copying entire directories (destination is "<sScratch>\Web"). 3389 # Should fail, as the corresponding flag is missing. 3392 # Ditto, with trailing slash. 3390 3393 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web', 3391 sDst = sScratchHst + "/"),3394 sDst = sScratchHst + "/"), 3392 3395 tdTestResult(fRc = False) ], 3393 # Next try with correctflag being set.3396 # Next try with the DirectoryCopyFlag_CopyIntoExisting flag being set. 3394 3397 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web', 3395 sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),3398 sDst = sScratchHst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3396 3399 tdTestResult(fRc = True) ], 3397 # Copying contents of directories (destination is "<sScratch>/"). 3400 # Ditto, with trailing slash. 3401 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web', 3402 sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3403 tdTestResult(fRc = True) ], 3404 # Copying contents of directories into a non-existing directory chain on the host which fail. 3398 3405 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\', 3399 sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3406 sDst = sScratchHst + "/not/existing/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3407 tdTestResult(fRc = False) ], 3408 # Copying contents of directories into a non-existing directory on the host, which should succeed. 3409 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\', 3410 sDst = sScratchHst + "/no-existing/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3400 3411 tdTestResult(fRc = True) ] 3401 3412 ]);
Note:
See TracChangeset
for help on using the changeset viewer.