Changeset 39582 in vbox
- Timestamp:
- Dec 12, 2011 1:40:09 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75344
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r39433 r39582 82 82 * An entry for a source element, including an optional DOS-like wildcard (*,?). 83 83 */ 84 typedef struct SOURCEFILEENTRY 85 { 86 SOURCEFILEENTRY(const char *pszSource, const char *pszFilter) 87 : mSource(pszSource), 88 mFilter(pszFilter) {} 89 SOURCEFILEENTRY(const char *pszSource) 90 : mSource(pszSource) 91 { 92 if ( !RTFileExists(pszSource) 93 && !RTDirExists(pszSource)) 94 { 95 /* No file and no directory -- maybe a filter? */ 96 char *pszFilename = RTPathFilename(pszSource); 97 if ( pszFilename 98 && strpbrk(pszFilename, "*?")) 99 { 100 /* Yep, get the actual filter part. */ 101 mFilter = RTPathFilename(pszSource); 102 /* Remove the filter from actual sourcec directory name. */ 103 RTPathStripFilename(mSource.mutableRaw()); 104 mSource.jolt(); 105 } 106 } 107 } 108 Utf8Str mSource; 109 Utf8Str mFilter; 110 } SOURCEFILEENTRY, *PSOURCEFILEENTRY; 84 class SOURCEFILEENTRY 85 { 86 public: 87 88 SOURCEFILEENTRY(const char *pszSource, const char *pszFilter) 89 : mSource(pszSource), 90 mFilter(pszFilter) {} 91 92 SOURCEFILEENTRY(const char *pszSource) 93 : mSource(pszSource) 94 { 95 Parse(pszSource); 96 } 97 98 const char* GetSource() const 99 { 100 return mSource.c_str(); 101 } 102 103 const char* GetFilter() const 104 { 105 return mFilter.c_str(); 106 } 107 108 private: 109 110 int Parse(const char *pszPath) 111 { 112 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 113 114 if ( !RTFileExists(pszPath) 115 && !RTDirExists(pszPath)) 116 { 117 /* No file and no directory -- maybe a filter? */ 118 char *pszFilename = RTPathFilename(pszPath); 119 if ( pszFilename 120 && strpbrk(pszFilename, "*?")) 121 { 122 /* Yep, get the actual filter part. */ 123 mFilter = RTPathFilename(pszPath); 124 /* Remove the filter from actual sourcec directory name. */ 125 RTPathStripFilename(mSource.mutableRaw()); 126 mSource.jolt(); 127 } 128 } 129 130 return VINF_SUCCESS; /* @todo */ 131 } 132 133 private: 134 135 Utf8Str mSource; 136 Utf8Str mFilter; 137 }; 111 138 typedef std::vector<SOURCEFILEENTRY> SOURCEVEC, *PSOURCEVEC; 112 139 … … 197 224 OUTPUTTYPE_UNIX2DOS = 20 198 225 }; 226 227 static int ctrlCopyDirExists(PCOPYCONTEXT pContext, bool bGuest, const char *pszDir, bool *fExists); 199 228 200 229 #endif /* VBOX_ONLY_DOCS */ … … 962 991 size_t srcOff = strlen(pszSourceRoot); 963 992 AssertReturn(srcOff, VERR_INVALID_PARAMETER); 964 int rc = RTPathJoin(szTranslated, sizeof(szTranslated), 965 pszDest, &pszSource[srcOff]); 993 994 char *pszDestPath = RTStrDup(pszDest); 995 AssertPtrReturn(pszDestPath, VERR_NO_MEMORY); 996 997 int rc; 998 if (!RTPathFilename(pszDestPath)) 999 { 1000 rc = RTPathJoin(szTranslated, sizeof(szTranslated), 1001 pszDestPath, &pszSource[srcOff]); 1002 } 1003 else 1004 { 1005 char *pszDestFileName = RTStrDup(RTPathFilename(pszDestPath)); 1006 if (pszDestFileName) 1007 { 1008 RTPathStripFilename(pszDestPath); 1009 rc = RTPathJoin(szTranslated, sizeof(szTranslated), 1010 pszDestPath, pszDestFileName); 1011 RTStrFree(pszDestFileName); 1012 } 1013 else 1014 rc = VERR_NO_MEMORY; 1015 } 1016 RTStrFree(pszDestPath); 1017 966 1018 if (RT_SUCCESS(rc)) 1019 { 967 1020 *ppszTranslated = RTStrDup(szTranslated); 1021 #ifdef DEBUG 1022 RTPrintf("Root: %s, Source: %s, Dest: %s, Translated: %s\n", 1023 pszSourceRoot, pszSource, pszDest, *ppszTranslated); 1024 #endif 1025 } 968 1026 return rc; 969 1027 } … … 972 1030 static int tstTranslatePath() 973 1031 { 1032 RTAssertSetMayPanic(false /* Do not freak out, please. */); 1033 974 1034 static struct 975 1035 { … … 983 1043 /* Invalid stuff. */ 984 1044 { NULL, NULL, NULL, NULL, VERR_INVALID_POINTER }, 1045 #ifdef RT_OS_WINDOWS 985 1046 /* Windows paths. */ 986 1047 { "c:\\foo", "c:\\foo\\bar.txt", "c:\\test", "c:\\test\\bar.txt", VINF_SUCCESS }, 987 { "c:\\foo", "c:\\foo\\baz\\bar.txt", "c:\\test", "c:\\test\\baz\\bar.txt", VINF_SUCCESS } 988 /* UNIX-like paths. */ 1048 { "c:\\foo", "c:\\foo\\baz\\bar.txt", "c:\\test", "c:\\test\\baz\\bar.txt", VINF_SUCCESS }, 1049 #else /* RT_OS_WINDOWS */ 1050 { "/home/test/foo", "/home/test/foo/bar.txt", "/opt/test", "/opt/test/bar.txt", VINF_SUCCESS }, 1051 { "/home/test/foo", "/home/test/foo/baz/bar.txt", "/opt/test", "/opt/test/baz/bar.txt", VINF_SUCCESS }, 1052 #endif /* !RT_OS_WINDOWS */ 989 1053 /* Mixed paths*/ 990 1054 /** @todo */ 1055 { NULL } 991 1056 }; 992 1057 993 int iTest = 0;1058 size_t iTest = 0; 994 1059 for (iTest; iTest < RT_ELEMENTS(aTests); iTest++) 995 1060 { … … 1037 1102 AssertPtrReturn(pszDir, VERR_INVALID_POINTER); 1038 1103 1104 bool fDirExists; 1105 if (ctrlCopyDirExists(pContext, pContext->fHostToGuest, pszDir, &fDirExists)) 1106 { 1107 if (pContext->fVerbose) 1108 RTPrintf("Directory \"%s\" already exists\n", pszDir); 1109 return VINF_SUCCESS; 1110 } 1111 1039 1112 if (pContext->fVerbose) 1040 1113 RTPrintf("Creating directory \"%s\" ...\n", pszDir); … … 1048 1121 HRESULT hrc = pContext->pGuest->DirectoryCreate(Bstr(pszDir).raw(), 1049 1122 Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(), 1050 700, DirectoryCreateFlag_Parents);1123 0700, DirectoryCreateFlag_Parents); 1051 1124 if (FAILED(hrc)) 1052 1125 rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); … … 1286 1359 1287 1360 if (pContext->fVerbose) 1288 RTPrintf("Processing directory: %s\n", szCurDir);1361 RTPrintf("Processing host directory: %s\n", szCurDir); 1289 1362 1290 1363 /* Flag indicating whether the current directory was created on the … … 1455 1528 1456 1529 if (pContext->fVerbose) 1457 RTPrintf("Processing directory: %s\n", szCurDir);1530 RTPrintf("Processing guest directory: %s\n", szCurDir); 1458 1531 1459 1532 /* Flag indicating whether the current directory was created on the … … 1761 1834 { 1762 1835 /* Last argument and no destination specified with 1763 * --target-directory yet? Then use the current argument1764 * as destination. */1836 * --target-directory yet? Then use the current 1837 * (= last) argument as destination. */ 1765 1838 if ( pArg->argc == GetState.iNext 1766 1839 && Utf8Dest.isEmpty()) … … 1820 1893 /* If the destination is a path, (try to) create it. */ 1821 1894 const char *pszDest = Utf8Dest.c_str(); 1822 AssertPtr(pszDest); 1823 size_t lenDest = strlen(pszDest); 1824 if ( lenDest 1825 ||pszDest[lenDest - 1] == '/' 1826 || pszDest[lenDest - 1] == '\\') 1895 if (!RTPathFilename(pszDest)) 1827 1896 { 1828 1897 vrc = ctrlCopyDirCreate(pContext, pszDest); 1898 } 1899 else 1900 { 1901 /* We assume we got a file name as destination -- so strip 1902 * the actual file name and make sure the appropriate 1903 * directories get created. */ 1904 char *pszDestDir = RTStrDup(pszDest); 1905 AssertPtr(pszDestDir); 1906 RTPathStripFilename(pszDestDir); 1907 vrc = ctrlCopyDirCreate(pContext, pszDestDir); 1908 RTStrFree(pszDestDir); 1829 1909 } 1830 1910 … … 1837 1917 for (unsigned long s = 0; s < vecSources.size(); s++) 1838 1918 { 1839 char *pszSource = RTStrDup(vecSources[s]. mSource.c_str());1919 char *pszSource = RTStrDup(vecSources[s].GetSource()); 1840 1920 AssertPtrBreakStmt(pszSource, vrc = VERR_NO_MEMORY); 1841 const char *pszFilter = vecSources[s]. mFilter.c_str();1921 const char *pszFilter = vecSources[s].GetFilter(); 1842 1922 if (!strlen(pszFilter)) 1843 1923 pszFilter = NULL; /* If empty filter then there's no filter :-) */ … … 1855 1935 1856 1936 /** @todo Files with filter?? */ 1857 bool f IsFile = false;1858 bool f Exists;1937 bool fSourceIsFile = false; 1938 bool fSourceExists; 1859 1939 1860 1940 size_t cchSource = strlen(pszSource); … … 1863 1943 { 1864 1944 if (pszFilter) /* Directory with filter (so use source root w/o the actual filter). */ 1865 vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &f Exists);1945 vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &fSourceExists); 1866 1946 else /* Regular directory without filter. */ 1867 vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &f Exists);1868 1869 if (f Exists)1947 vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fSourceExists); 1948 1949 if (fSourceExists) 1870 1950 { 1871 1951 /* Strip trailing slash from our source element so that other functions … … 1876 1956 else 1877 1957 { 1878 vrc = ctrlCopyFileExistsOnSource(pContext, pszSource, &f Exists);1958 vrc = ctrlCopyFileExistsOnSource(pContext, pszSource, &fSourceExists); 1879 1959 if ( RT_SUCCESS(vrc) 1880 && f Exists)1960 && fSourceExists) 1881 1961 { 1882 f IsFile = true;1962 fSourceIsFile = true; 1883 1963 } 1884 1964 } 1885 1965 1886 1966 if ( RT_SUCCESS(vrc) 1887 && f Exists)1888 { 1889 if (f IsFile)1967 && fSourceExists) 1968 { 1969 if (fSourceIsFile) 1890 1970 { 1891 1971 /* Single file. */ … … 1914 1994 1915 1995 if ( RT_SUCCESS(vrc) 1916 && !f Exists)1996 && !fSourceExists) 1917 1997 { 1918 1998 RTMsgError("Warning: Source \"%s\" does not exist, skipping!\n",
Note:
See TracChangeset
for help on using the changeset viewer.