VirtualBox

Changeset 37404 in vbox


Ignore:
Timestamp:
Jun 10, 2011 10:33:10 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72201
Message:

VBoxService/Toolbox: Update for ls.

File:
1 edited

Legend:

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

    r37403 r37404  
    4747
    4848#define LS_OPT_MACHINE_READABLE                 1000
     49
     50typedef enum VBOXSERVICETOOLBOXLSFLAG
     51{
     52    VBOXSERVICETOOLBOXLSFLAG_NONE =             0,
     53    VBOXSERVICETOOLBOXLSFLAG_RECURSIVE =        0x00000001,
     54    VBOXSERVICETOOLBOXLSFLAG_LONG =             0x00000002,
     55    VBOXSERVICETOOLBOXLSFLAG_PARSEABLE =        0x00000004,
     56    VBOXSERVICETOOLBOXLSFLAG_SYMLINKS =         0x00000008
     57} VBOXSERVICETOOLBOXLSFLAG;
    4958
    5059/* Enable the following define to be able to debug/invoke the toolbox
     
    397406 * @return  IPRT status code.
    398407 * @param   pszDir                  Directory (path) to ouptut.
    399  * @param   fRecursive              Flag indicating whether recursive directory handling
    400  *                                  is wanted or not.
    401  * @param   fLong                   Flag indicating whether long output is required or not.
    402  * @param   fParseable              Flag indicating whether machine parseable output
    403  *                                  is required or not
    404  */
    405 static int VBoxServiceToolboxLsOutput(const char *pszDir,
    406                                       bool fRecursive, bool fLong, bool fParseable)
     408 * @param   uFlags                  Flags of type VBOXSERVICETOOLBOXLSFLAG.
     409 */
     410static int VBoxServiceToolboxLsOutput(const char *pszDir, uint32_t uFlags)
    407411{
    408412    AssertPtrReturn(pszDir, VERR_INVALID_PARAMETER);
    409413
    410     if (fParseable)
     414    if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE)
    411415        RTPrintf("dname=%s%c", pszDir, 0);
     416    else if (uFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE)
     417        RTPrintf("%s:\n", pszDir);
    412418
    413419    char szPathAbs[RTPATH_MAX + 1];
     
    423429    if (RT_FAILURE(rc))
    424430    {
    425         RTMsgError("ls: Failed to open '%s', rc=%Rrc\n", szPathAbs, rc);
     431        RTMsgError("ls: Failed to open directory '%s', rc=%Rrc\n", szPathAbs, rc);
    426432        return rc;
    427433    }
     
    486492            /** @todo sticy bits++ */
    487493
    488             if (!fLong)
    489             {
    490                 if (fParseable)
     494            if (!(uFlags & VBOXSERVICETOOLBOXLSFLAG_LONG))
     495            {
     496                if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE)
    491497                {
    492498                    /** @todo Skip node_id if not present/available! */
     
    499505                             cFileType, pNodeIt->dirEntry.cbName, pNodeIt->dirEntry.szName);
    500506
    501                 if (fParseable) /* End of data block. */
     507                if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) /* End of data block. */
    502508                    RTPrintf("%c%c", 0, 0);
    503509            }
    504510            else
    505511            {
    506                 if (fParseable)
     512                if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE)
    507513                {
    508514                    RTPrintf("ftype=%c%c", cFileType, 0);
     
    609615
    610616        /* If everything went fine we do the second run (if needed) ... */
    611         if (RT_SUCCESS(rc) && fRecursive)
     617        if (   RT_SUCCESS(rc)
     618            && (uFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE))
    612619        {
    613620            /* Process all sub-directories. */
     
    618625                switch (fMode & RTFS_TYPE_MASK)
    619626                {
    620                     //case RTFS_TYPE_SYMLINK:
     627                    case RTFS_TYPE_SYMLINK:
     628                        if (!(uFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS))
     629                            break;
     630                        /* Fall through is intentional. */
    621631                    case RTFS_TYPE_DIRECTORY:
    622632                        {
     
    628638                                continue;
    629639                            }
    630                             rc = VBoxServiceToolboxLsOutput(pNodeIt->dirEntry.szName, fRecursive,
    631                                                             fLong, fParseable);
     640
     641                            char szPath[RTPATH_MAX];
     642                            rc = RTPathJoin(szPath, sizeof(szPath),
     643                                            pszDir, pNodeIt->dirEntry.szName);
     644                            if (RT_SUCCESS(rc))
     645                                rc = VBoxServiceToolboxLsOutput(szPath, uFlags);
    632646                        }
    633647                        break;
     
    685699    int rc = VINF_SUCCESS;
    686700    bool fVerbose = false;
    687     bool fLong = false;
    688     bool fMachineReadable = false;
    689     bool fRecursive = false;
     701    uint32_t fFlags = 0;
    690702
    691703    /* Init file list. */
     
    704716
    705717            case 'l': /* Print long format. */
    706                 fLong = true;
     718                fFlags |= VBOXSERVICETOOLBOXLSFLAG_LONG;
    707719                break;
    708720
    709721            case LS_OPT_MACHINE_READABLE:
    710                 fMachineReadable = true;
     722                fFlags |= VBOXSERVICETOOLBOXLSFLAG_PARSEABLE;
    711723                break;
    712724
    713725            case 'R': /* Recursive processing. */
    714                 fRecursive = true;
     726                fFlags |= VBOXSERVICETOOLBOXLSFLAG_RECURSIVE;
    715727                break;
    716728
     
    758770
    759771        /* Print magic/version. */
    760         if (fMachineReadable)
     772        if (fFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE)
    761773            RTPrintf("hdr_id=vbt_ls%chdr_ver=%u%c", 0, 1 /* Version 1 */, 0);
    762774
     
    764776        RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node)
    765777        {
    766             rc = VBoxServiceToolboxLsOutput(pNodeIt->pszName,
    767                                             fRecursive, fLong, fMachineReadable);
     778            rc = VBoxServiceToolboxLsOutput(pNodeIt->pszName, fFlags);
    768779            if (RT_FAILURE(rc))
    769780                RTMsgError("ls: Failed while enumerating directory '%s', rc=%Rrc\n",
     
    771782        }
    772783
    773         if (fMachineReadable) /* Output termination. */
     784        if (fFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) /* Output termination. */
    774785            RTPrintf("%c%c%c%c", 0, 0, 0, 0);
    775786    }
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