VirtualBox

Ignore:
Timestamp:
Jul 18, 2011 12:49:31 PM (14 years ago)
Author:
vboxsync
Message:

VBoxServiceToolBox: Addressed misc. todos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp

    r37952 r38015  
    4747*   Defined Constants And Macros                                               *
    4848*******************************************************************************/
     49
    4950/** Options indices for "vbox_cat". */
    50 #define CAT_OPT_NO_CONTENT_INDEXED              1000
     51typedef enum VBOXSERVICETOOLBOXCATOPT
     52{
     53    VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED = 1000
     54} VBOXSERVICETOOLBOXCATOPT;
     55
    5156/** Options indices for "vbox_ls". */
    52 #define LS_OPT_MACHINE_READABLE                 1000
     57typedef enum VBOXSERVICETOOLBOXLSOPT
     58{
     59    VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE = 1000,
     60    VBOXSERVICETOOLBOXLSOPT_VERBOSE
     61} VBOXSERVICETOOLBOXLSOPT;
     62
    5363/** Options indices for "vbox_stat". */
    54 #define STAT_OPT_MACHINE_READABLE               1000
     64typedef enum VBOXSERVICETOOLBOXSTATOPT
     65{
     66    VBOXSERVICETOOLBOXSTATOPT_MACHINE_READABLE = 1000
     67} VBOXSERVICETOOLBOXSTATOPT;
     68
     69
    5570/** Flags for "vbox_ls". */
    5671typedef enum VBOXSERVICETOOLBOXLSFLAG
     
    268283    {
    269284        /* Sorted by short ops. */
    270         { "--show-all",            'a',                         RTGETOPT_REQ_NOTHING },
    271         { "--number-nonblank",     'b',                         RTGETOPT_REQ_NOTHING},
    272         { NULL,                    'e',                         RTGETOPT_REQ_NOTHING},
    273         { NULL,                    'E',                         RTGETOPT_REQ_NOTHING},
    274         { "--flags",               'f',                         RTGETOPT_REQ_STRING},
    275         { "--no-content-indexed",  CAT_OPT_NO_CONTENT_INDEXED,  RTGETOPT_REQ_NOTHING},
    276         { "--number",              'n',                         RTGETOPT_REQ_NOTHING},
    277         { "--output",              'o',                         RTGETOPT_REQ_STRING},
    278         { "--squeeze-blank",       's',                         RTGETOPT_REQ_NOTHING},
    279         { NULL,                    't',                         RTGETOPT_REQ_NOTHING},
    280         { "--show-tabs",           'T',                         RTGETOPT_REQ_NOTHING},
    281         { NULL,                    'u',                         RTGETOPT_REQ_NOTHING},
    282         { "--show-noneprinting",   'v',                         RTGETOPT_REQ_NOTHING}
     285        { "--show-all",            'a',                                           RTGETOPT_REQ_NOTHING },
     286        { "--number-nonblank",     'b',                                           RTGETOPT_REQ_NOTHING},
     287        { NULL,                    'e',                                           RTGETOPT_REQ_NOTHING},
     288        { NULL,                    'E',                                           RTGETOPT_REQ_NOTHING},
     289        { "--flags",               'f',                                           RTGETOPT_REQ_STRING},
     290        { "--no-content-indexed",  VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED,   RTGETOPT_REQ_NOTHING},
     291        { "--number",              'n',                                           RTGETOPT_REQ_NOTHING},
     292        { "--output",              'o',                                           RTGETOPT_REQ_STRING},
     293        { "--squeeze-blank",       's',                                           RTGETOPT_REQ_NOTHING},
     294        { NULL,                    't',                                           RTGETOPT_REQ_NOTHING},
     295        { "--show-tabs",           'T',                                           RTGETOPT_REQ_NOTHING},
     296        { NULL,                    'u',                                           RTGETOPT_REQ_NOTHING},
     297        { "--show-noneprinting",   'v',                                           RTGETOPT_REQ_NOTHING}
    283298    };
    284299
     
    341356                return RTEXITCODE_SUCCESS;
    342357
    343             case CAT_OPT_NO_CONTENT_INDEXED:
     358            case VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED:
    344359                fFlags |= RTFILE_O_NOT_CONTENT_INDEXED;
    345360                break;
     
    717732    static const RTGETOPTDEF s_aOptions[] =
    718733    {
    719         { "--machinereadable", LS_OPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING },
    720         { "--dereference",     'L',                     RTGETOPT_REQ_NOTHING },
    721         { NULL,                'l',                     RTGETOPT_REQ_NOTHING },
    722         { NULL,                'R',                     RTGETOPT_REQ_NOTHING },
    723         { "--verbose",         'v',                     RTGETOPT_REQ_NOTHING}
     734        { "--machinereadable", VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE,      RTGETOPT_REQ_NOTHING },
     735        { "--dereference",     'L',                                           RTGETOPT_REQ_NOTHING },
     736        { NULL,                'l',                                           RTGETOPT_REQ_NOTHING },
     737        { NULL,                'R',                                           RTGETOPT_REQ_NOTHING },
     738        { "--verbose",         VBOXSERVICETOOLBOXLSOPT_VERBOSE,               RTGETOPT_REQ_NOTHING}
    724739    };
    725740
     
    758773                break;
    759774
    760             case LS_OPT_MACHINE_READABLE:
     775            case VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE:
    761776                fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE;
    762777                break;
     
    766781                break;
    767782
    768             case 'v': /** @todo r=bird: "man ls" -> "-v natural sort of (version) numbers within text" */
     783            case VBOXSERVICETOOLBOXLSOPT_VERBOSE:
    769784                fVerbose = true;
    770785                break;
     
    816831        RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node)
    817832        {
    818             /** @todo r=bird: Call RTPathQueryInfoEx directly (RTFileExists
    819              *        does it under the hood) and skip the RTFileOpen stuff!
    820              *        /bin/ls can list full details for files you cannot open.
    821              *
    822              * Just try the following:
    823              * @code
    824                       $ echo > testfile
    825                       $ chmod 600 testfile
    826                       $ sudo chown root:root testfile
    827                       $ ls -la testfile
    828              * @endcode
    829              */
    830 
    831833            if (RTFileExists(pNodeIt->pszName))
    832834            {
    833                 RTFILE file;
    834                 rc = RTFileOpen(&file, pNodeIt->pszName, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ);
    835                 if (RT_SUCCESS(rc))
     835                RTFSOBJINFO objInfo;
     836                int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo,
     837                                            RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /* @todo Follow link? */);
     838                if (RT_FAILURE(rc2))
    836839                {
    837                     RTFSOBJINFO objInfo;
    838                     rc = RTFileQueryInfo(file, &objInfo, RTFSOBJATTRADD_UNIX);
    839                     if (RT_SUCCESS(rc))
    840                     {
    841                         rc = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName, strlen(pNodeIt->pszName),
    842                                                            fOutputFlags, &objInfo);
    843                     }
    844                     else
    845                         RTMsgError("Unable to query information for '%s', rc=%Rrc\n",
    846                                    pNodeIt->pszName, rc);
    847                     RTFileClose(file);
     840                    RTMsgError("Cannot access '%s': No such file or directory\n",
     841                               pNodeIt->pszName);
     842                    rc = VERR_FILE_NOT_FOUND;
     843                    /* Do not break here -- process every element in the list
     844                     * and keep failing rc. */
    848845                }
    849846                else
    850                     RTMsgError("Failed opening '%s', rc=%Rrc\n",
    851                                pNodeIt->pszName, rc);
     847                {
     848                    rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName,
     849                                                        strlen(pNodeIt->pszName) /* cbName */,
     850                                                        fOutputFlags,
     851                                                        &objInfo);
     852                    if (RT_FAILURE(rc2))
     853                        rc = rc2;
     854                }
    852855            }
    853856            else
    854                 rc = VBoxServiceToolboxLsHandleDir(pNodeIt->pszName,
    855                                                    fFlags, fOutputFlags);
    856             if (RT_FAILURE(rc))
    857                 RTMsgError("Failed while enumerating '%s', rc=%Rrc\n",
    858                            pNodeIt->pszName, rc);
     857            {
     858                int rc2 = VBoxServiceToolboxLsHandleDir(pNodeIt->pszName,
     859                                                        fFlags, fOutputFlags);
     860                if (RT_FAILURE(rc2))
     861                    rc = rc2;
     862            }
    859863        }
    860864
     
    958962                                          ValueUnion.psz, rc);
    959963                if (fVerbose)
    960                     RTMsgInfo("Created directory 's', mode %#RTfmode\n", ValueUnion.psz, fDirMode);
     964                    RTMsgInfo("Created directory '%s', mode %#RTfmode\n", ValueUnion.psz, fDirMode);
    961965                cDirsCreated++;
    962966                break;
     
    986990    static const RTGETOPTDEF s_aOptions[] =
    987991    {
    988         { "--file-system",     'f',                       RTGETOPT_REQ_NOTHING },
    989         { "--dereference",     'L',                       RTGETOPT_REQ_NOTHING },
    990         { "--machinereadable", STAT_OPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING },
    991         { "--terse",           't',                       RTGETOPT_REQ_NOTHING },
    992         { "--verbose",         'v',                       RTGETOPT_REQ_NOTHING }
     992        { "--file-system",     'f',                                          RTGETOPT_REQ_NOTHING },
     993        { "--dereference",     'L',                                          RTGETOPT_REQ_NOTHING },
     994        { "--machinereadable", VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE,    RTGETOPT_REQ_NOTHING },
     995        { "--terse",           't',                                          RTGETOPT_REQ_NOTHING },
     996        { "--verbose",         'v',                                          RTGETOPT_REQ_NOTHING }
    993997    };
    994998
     
    10201024                break;
    10211025
    1022             case LS_OPT_MACHINE_READABLE:
     1026            case VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE:
    10231027                fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE;
    10241028                break;
     
    10611065        RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node)
    10621066        {
    1063             /** @todo r=bird: Use RTPathQueryInfoEx!  The tool is called
    1064              *        'stat' because it's just a wrapper for 'stat()',
    1065              *        right?  Our equvialent to the 'stat()' call is
    1066              *        RTPathQueryInfoEx().  Same permission issues as above
    1067              *        with 'ls'. */
    1068             /* Only check for file existence for now. */
    10691067            RTFSOBJINFO objInfo;
    1070             int rc2 = VINF_SUCCESS; /* Temporary rc to keep original rc. */
    1071             if (RTFileExists(pNodeIt->pszName))
    1072             {
    1073                 RTFILE file;
    1074                 rc2 = RTFileOpen(&file, pNodeIt->pszName, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ);
    1075                 if (RT_SUCCESS(rc2))
    1076                 {
    1077                     rc2 = RTFileQueryInfo(file, &objInfo, RTFSOBJATTRADD_UNIX);
    1078                     if (RT_FAILURE(rc2))
    1079                         RTMsgError("Unable to query information for '%s', rc=%Rrc\n",
    1080                                    pNodeIt->pszName, rc2);
    1081                     RTFileClose(file);
    1082                 }
    1083                 else
    1084                     RTMsgError("Failed opening '%s', rc=%Rrc\n",
    1085                                pNodeIt->pszName, rc2);
    1086 
    1087                 if (RT_FAILURE(rc2))
    1088                     rc = rc2;
    1089             }
    1090             else if (RTDirExists(pNodeIt->pszName))
    1091             {
    1092                 PRTDIR pDir;
    1093                 rc2 = RTDirOpen(&pDir, pNodeIt->pszName);
    1094                 if (RT_SUCCESS(rc2))
    1095                 {
    1096                     rc2 = RTDirQueryInfo(pDir, &objInfo, RTFSOBJATTRADD_UNIX);
    1097                     RTDirClose(pDir);
    1098                 }
    1099             }
    1100             else
     1068            int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo,
     1069                                        RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /* @todo Follow link? */);
     1070            if (RT_FAILURE(rc2))
    11011071            {
    11021072                RTMsgError("Cannot stat for '%s': No such file or directory\n",
     
    11061076                 * and keep failing rc. */
    11071077            }
    1108 
    1109             if (RT_SUCCESS(rc2))
     1078            else
    11101079            {
    11111080                rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette