Changeset 105333 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Jul 16, 2024 2:07:58 AM (10 months ago)
- svn:sync-xref-src-repo-rev:
- 163986
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r105087 r105333 1836 1836 { "--name", 'n', RTGETOPT_REQ_STRING }, 1837 1837 { "-name", 'n', RTGETOPT_REQ_STRING }, // deprecated 1838 { "--transient", 't', RTGETOPT_REQ_NOTHING }, 1839 { "-transient", 't', RTGETOPT_REQ_NOTHING }, // deprecated 1838 { "--automount", 'a', RTGETOPT_REQ_BOOL }, 1839 { "-automount", 'a', RTGETOPT_REQ_BOOL }, // deprecated 1840 { "--readonly", 'r', RTGETOPT_REQ_BOOL }, 1841 { "-readonly", 'r', RTGETOPT_REQ_BOOL }, // deprecated 1840 1842 { "--symlink-policy", 's', RTGETOPT_REQ_STRING }, 1841 1843 { "-symlink-policy", 's', RTGETOPT_REQ_STRING }, // deprecated 1844 { "--auto-mount-point", 'm', RTGETOPT_REQ_STRING }, 1845 { "-auto-mount-point", 'm', RTGETOPT_REQ_STRING }, // deprecated 1842 1846 }; 1843 1847 const char *pszMachineName = NULL; 1844 1848 const char *pszName = NULL; 1845 bool fTransient = false; 1849 int fWritable = -1; 1850 int fAutoMount = -1; 1851 const char *pszAutoMountPoint = NULL; 1846 1852 SymlinkPolicy_T enmSymlinkPolicy = SymlinkPolicy_None; 1847 1853 … … 1857 1863 pszName = ValueUnion.psz; 1858 1864 break; 1859 case 't': 1860 fTransient = true; 1865 case 'r': 1866 fWritable = !ValueUnion.f; 1867 break; 1868 case 'a': 1869 fAutoMount = ValueUnion.f; 1870 break; 1871 case 'm': 1872 pszAutoMountPoint = ValueUnion.psz; 1861 1873 break; 1862 1874 case 's': … … 1881 1893 return errorSyntax(Misc::tr("No shared folder name (--name) was supplied.")); 1882 1894 1883 /* the only supported option at the moment so it must be set */ 1884 if (enmSymlinkPolicy == SymlinkPolicy_None) 1885 return errorSyntax(Misc::tr("No symbolic link policy (--symlink-policy) was supplied.")); 1895 if (enmSymlinkPolicy == SymlinkPolicy_None && fWritable == -1 && fAutoMount == -1 && !pszAutoMountPoint) 1896 return errorSyntax(Misc::tr("No shared folder attributes specified.")); 1886 1897 1887 1898 /* … … 1893 1904 1894 1905 HRESULT hrc; 1895 if (fTransient) 1896 { 1897 /* open an existing session for the VM */ 1898 CHECK_ERROR_RET(ptrMachine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE); 1899 1900 /* get the session machine */ 1901 ComPtr<IMachine> ptrSessionMachine; 1902 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(ptrSessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1903 1904 /* get the session console */ 1905 ComPtr<IConsole> ptrConsole; 1906 CHECK_ERROR_RET(a->session, COMGETTER(Console)(ptrConsole.asOutParam()), RTEXITCODE_FAILURE); 1907 if (ptrConsole.isNull()) 1908 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Machine '%s' is not currently running.\n"), pszMachineName); 1909 1910 /* find the desired transient shared folder to modify */ 1911 com::SafeIfaceArray <ISharedFolder> sharedFolders; 1912 CHECK_ERROR_RET(ptrConsole, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders)), RTEXITCODE_FAILURE); 1913 if (sharedFolders.size() == 0) 1914 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Machine '%s' has no transient shared folders configured.\n"), 1915 pszMachineName); 1916 1917 bool fFound = false; 1918 for (size_t i = 0; i < sharedFolders.size(); ++i) 1919 { 1920 ComPtr<ISharedFolder> sharedFolder = sharedFolders[i]; 1921 Bstr bstrSharedFolderName; 1922 CHECK_ERROR_RET(sharedFolder, COMGETTER(Name)(bstrSharedFolderName.asOutParam()), RTEXITCODE_FAILURE); 1923 Utf8Str strSharedFolderName(bstrSharedFolderName); 1924 if (!RTStrCmp(strSharedFolderName.c_str(), pszName)) 1925 { 1906 /* Open a session for the VM using an exclusive lock as this is for permanent shared folders. 1907 * Support for modifying transient shared folders hasn't been implemented yet. */ 1908 CHECK_ERROR_RET(ptrMachine, LockMachine(a->session, LockType_Write), RTEXITCODE_FAILURE); 1909 1910 /* get the mutable session machine */ 1911 ComPtr<IMachine> ptrSessionMachine; 1912 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(ptrSessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1913 1914 /* find the desired shared folder to modify */ 1915 com::SafeIfaceArray <ISharedFolder> sharedFolders; 1916 CHECK_ERROR_RET(ptrSessionMachine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders)), RTEXITCODE_FAILURE); 1917 if (sharedFolders.size() == 0) 1918 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Machine '%s' has no shared folders configured.\n"), 1919 pszMachineName); 1920 1921 bool fFound = false; 1922 for (size_t i = 0; i < sharedFolders.size(); ++i) 1923 { 1924 ComPtr<ISharedFolder> sharedFolder = sharedFolders[i]; 1925 Bstr bstrSharedFolderName; 1926 CHECK_ERROR_RET(sharedFolder, COMGETTER(Name)(bstrSharedFolderName.asOutParam()), RTEXITCODE_FAILURE); 1927 Utf8Str strSharedFolderName(bstrSharedFolderName); 1928 if (!RTStrCmp(strSharedFolderName.c_str(), pszName)) 1929 { 1930 fFound = true; 1931 if (enmSymlinkPolicy != SymlinkPolicy_None) 1926 1932 CHECK_ERROR_RET(sharedFolder, COMSETTER(SymlinkPolicy)(enmSymlinkPolicy), RTEXITCODE_FAILURE); 1927 fFound = true; 1928 break; 1929 } 1930 } 1931 if (!fFound) 1932 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Could not find a transient shared folder named '%s'.\n"), 1933 pszName); 1934 1935 CHECK_ERROR_RET(a->session, UnlockMachine(), RTEXITCODE_FAILURE); 1936 } 1937 else 1938 { 1939 /* open a session for the VM */ 1940 CHECK_ERROR_RET(ptrMachine, LockMachine(a->session, LockType_Write), RTEXITCODE_FAILURE); 1941 1942 /* get the mutable session machine */ 1943 ComPtr<IMachine> ptrSessionMachine; 1944 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(ptrSessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1945 1946 /* find the desired shared folder to modify */ 1947 com::SafeIfaceArray <ISharedFolder> sharedFolders; 1948 CHECK_ERROR_RET(ptrSessionMachine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sharedFolders)), RTEXITCODE_FAILURE); 1949 if (sharedFolders.size() == 0) 1950 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Machine '%s' has no shared folders configured.\n"), 1951 pszMachineName); 1952 1953 bool fFound = false; 1954 for (size_t i = 0; i < sharedFolders.size(); ++i) 1955 { 1956 ComPtr<ISharedFolder> sharedFolder = sharedFolders[i]; 1957 Bstr bstrSharedFolderName; 1958 CHECK_ERROR_RET(sharedFolder, COMGETTER(Name)(bstrSharedFolderName.asOutParam()), RTEXITCODE_FAILURE); 1959 Utf8Str strSharedFolderName(bstrSharedFolderName); 1960 if (!RTStrCmp(strSharedFolderName.c_str(), pszName)) 1961 { 1962 CHECK_ERROR_RET(sharedFolder, COMSETTER(SymlinkPolicy)(enmSymlinkPolicy), RTEXITCODE_FAILURE); 1963 fFound = true; 1964 break; 1965 } 1966 } 1967 if (!fFound) 1968 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Could not find a shared folder named '%s'.\n"), pszName); 1969 1970 /* commit and close the session */ 1971 if (SUCCEEDED(hrc)) 1972 CHECK_ERROR(ptrSessionMachine, SaveSettings()); 1973 1974 CHECK_ERROR_RET(a->session, UnlockMachine(), RTEXITCODE_FAILURE); 1975 } 1933 if (fWritable != -1) 1934 CHECK_ERROR_RET(sharedFolder, COMSETTER(Writable)((BOOL)fWritable), RTEXITCODE_FAILURE); 1935 if (fAutoMount != -1) 1936 CHECK_ERROR_RET(sharedFolder, COMSETTER(AutoMount)((BOOL)fAutoMount), RTEXITCODE_FAILURE); 1937 if (pszAutoMountPoint) 1938 CHECK_ERROR_RET(sharedFolder, COMSETTER(AutoMountPoint) (Bstr(pszAutoMountPoint).raw()), RTEXITCODE_FAILURE); 1939 break; 1940 } 1941 } 1942 if (!fFound) 1943 return RTMsgErrorExit(RTEXITCODE_FAILURE, Misc::tr("Could not find a shared folder named '%s'.\n"), pszName); 1944 1945 /* commit and close the session */ 1946 if (SUCCEEDED(hrc)) 1947 CHECK_ERROR(ptrSessionMachine, SaveSettings()); 1948 1949 CHECK_ERROR_RET(a->session, UnlockMachine(), RTEXITCODE_FAILURE); 1976 1950 1977 1951 return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.