Changeset 105018 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jun 25, 2024 11:06:29 AM (5 months ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r105016 r105018 799 799 } 800 800 801 static const char *symlinkPolicyToName(SymlinkPolicy_T enmSymlinkPolicy)802 {803 switch (enmSymlinkPolicy)804 {805 case SymlinkPolicy_AllowedToAnyTarget:806 return ("any");807 case SymlinkPolicy_AllowedInShareSubtree:808 return ("subtree");809 case SymlinkPolicy_AllowedToRelativeTargets:810 return ("relative");811 case SymlinkPolicy_Forbidden:812 return("forbidden");813 default:814 return("none");815 }816 }817 818 801 /** Shows a shared folder. */ 819 802 static HRESULT showSharedFolder(ComPtr<ISharedFolder> &sf, VMINFO_DETAILS details, const char *pszDesc, … … 822 805 Bstr name, hostPath, bstrAutoMountPoint; 823 806 BOOL writable = FALSE, fAutoMount = FALSE; 824 SymlinkPolicy_T enmSymlinkPolicy = SymlinkPolicy_None;825 807 CHECK_ERROR2I_RET(sf, COMGETTER(Name)(name.asOutParam()), hrcCheck); 826 808 CHECK_ERROR2I_RET(sf, COMGETTER(HostPath)(hostPath.asOutParam()), hrcCheck); … … 828 810 CHECK_ERROR2I_RET(sf, COMGETTER(AutoMount)(&fAutoMount), hrcCheck); 829 811 CHECK_ERROR2I_RET(sf, COMGETTER(AutoMountPoint)(bstrAutoMountPoint.asOutParam()), hrcCheck); 830 CHECK_ERROR2I_RET(sf, COMGETTER(SymlinkPolicy)(&enmSymlinkPolicy), hrcCheck);831 812 832 813 if (fFirst && details != VMINFO_MACHINEREADABLE) … … 843 824 name.raw(), hostPath.raw(), pszDesc, writable ? Info::tr("writable") : Info::tr("readonly"), 844 825 fAutoMount ? Info::tr(", auto-mount") : ""); 845 if (enmSymlinkPolicy != SymlinkPolicy_None)846 RTPrintf(Info::tr(", symlink-policy: %s"), symlinkPolicyToName(enmSymlinkPolicy));847 826 if (bstrAutoMountPoint.isNotEmpty()) 848 827 RTPrintf(Info::tr(", mount-point: '%ls'\n"), bstrAutoMountPoint.raw()); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r105016 r105018 1637 1637 case VINF_GETOPT_NOT_OPTION: 1638 1638 if (pszMachineName) 1639 return errorArgument(Misc::tr("Machine name given more than once: first '%s', then '%s'"),1639 return errorArgument(Misc::tr("Machine name is given more than once: first '%s', then '%s'"), 1640 1640 pszMachineName, ValueUnion.psz); 1641 1641 pszMachineName = ValueUnion.psz; … … 1749 1749 case VINF_GETOPT_NOT_OPTION: 1750 1750 if (pszMachineName) 1751 return errorArgument(Misc::tr("Machine name given more than once: first '%s', then '%s'"),1751 return errorArgument(Misc::tr("Machine name is given more than once: first '%s', then '%s'"), 1752 1752 pszMachineName, ValueUnion.psz); 1753 1753 pszMachineName = ValueUnion.psz; … … 1810 1810 } 1811 1811 1812 static SymlinkPolicy_T nameToSymlinkPolicy(const char *pszName)1813 {1814 if (!RTStrICmp(pszName, "forbidden"))1815 return SymlinkPolicy_Forbidden;1816 if (!RTStrICmp(pszName, "subtree"))1817 return SymlinkPolicy_AllowedInShareSubtree;1818 if (!RTStrICmp(pszName, "relative"))1819 return SymlinkPolicy_AllowedToRelativeTargets;1820 if (!RTStrICmp(pszName, "any"))1821 return SymlinkPolicy_AllowedToAnyTarget;1822 1823 return SymlinkPolicy_None;1824 }1825 1826 /**1827 * modify shared folder properties1828 */1829 static RTEXITCODE handleSharedFolderModify(HandlerArg *a)1830 {1831 /*1832 * Parse arguments (argv[0] == subcommand).1833 */1834 static const RTGETOPTDEF s_aModifyOptions[] =1835 {1836 { "--name", 'n', RTGETOPT_REQ_STRING },1837 { "-name", 'n', RTGETOPT_REQ_STRING }, // deprecated1838 { "--transient", 't', RTGETOPT_REQ_NOTHING },1839 { "-transient", 't', RTGETOPT_REQ_NOTHING }, // deprecated1840 { "--symlink-policy", 's', RTGETOPT_REQ_STRING },1841 { "-symlink-policy", 's', RTGETOPT_REQ_STRING }, // deprecated1842 };1843 const char *pszMachineName = NULL;1844 const char *pszName = NULL;1845 bool fTransient = false;1846 SymlinkPolicy_T enmSymlinkPolicy = SymlinkPolicy_None;1847 1848 RTGETOPTSTATE GetState;1849 RTGetOptInit(&GetState, a->argc, a->argv, s_aModifyOptions, RT_ELEMENTS(s_aModifyOptions), 1 /*iFirst*/, 0 /*fFlags*/);1850 int c;1851 RTGETOPTUNION ValueUnion;1852 while ((c = RTGetOpt(&GetState, &ValueUnion)))1853 {1854 switch (c)1855 {1856 case 'n':1857 pszName = ValueUnion.psz;1858 break;1859 case 't':1860 fTransient = true;1861 break;1862 case 's':1863 enmSymlinkPolicy = nameToSymlinkPolicy(ValueUnion.psz);1864 if (enmSymlinkPolicy == SymlinkPolicy_None)1865 return errorArgument(Misc::tr("Invalid --symlink-policy argument '%s'"), ValueUnion.psz);1866 break;1867 case VINF_GETOPT_NOT_OPTION:1868 if (pszMachineName)1869 return errorArgument(Misc::tr("Machine name given more than once: first '%s', then '%s'"),1870 pszMachineName, ValueUnion.psz);1871 pszMachineName = ValueUnion.psz;1872 break;1873 default:1874 return errorGetOpt(c, &ValueUnion);1875 }1876 }1877 1878 if (!pszMachineName)1879 return errorSyntax(Misc::tr("No machine was specified"));1880 if (!pszName)1881 return errorSyntax(Misc::tr("No shared folder name (--name) was supplied."));1882 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."));1886 1887 /*1888 * Done parsing, do some real work.1889 */1890 ComPtr<IMachine> ptrMachine;1891 CHECK_ERROR2I_RET(a->virtualBox, FindMachine(Bstr(pszMachineName).raw(), ptrMachine.asOutParam()), RTEXITCODE_FAILURE);1892 AssertReturn(ptrMachine.isNotNull(), RTEXITCODE_FAILURE);1893 1894 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 {1926 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 else1938 {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 }1976 1977 return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;1978 }1979 1812 1980 1813 RTEXITCODE handleSharedFolder(HandlerArg *a) … … 1993 1826 setCurrentSubcommand(HELP_SCOPE_SHAREDFOLDER_REMOVE); 1994 1827 return handleSharedFolderRemove(a); 1995 }1996 1997 if (!strcmp(a->argv[0], "modify"))1998 {1999 setCurrentSubcommand(HELP_SCOPE_SHAREDFOLDER_MODIFY);2000 return handleSharedFolderModify(a);2001 1828 } 2002 1829
Note:
See TracChangeset
for help on using the changeset viewer.