Changeset 37404 in vbox
- Timestamp:
- Jun 10, 2011 10:33:10 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 72201
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r37403 r37404 47 47 48 48 #define LS_OPT_MACHINE_READABLE 1000 49 50 typedef 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; 49 58 50 59 /* Enable the following define to be able to debug/invoke the toolbox … … 397 406 * @return IPRT status code. 398 407 * @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 */ 410 static int VBoxServiceToolboxLsOutput(const char *pszDir, uint32_t uFlags) 407 411 { 408 412 AssertPtrReturn(pszDir, VERR_INVALID_PARAMETER); 409 413 410 if ( fParseable)414 if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) 411 415 RTPrintf("dname=%s%c", pszDir, 0); 416 else if (uFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE) 417 RTPrintf("%s:\n", pszDir); 412 418 413 419 char szPathAbs[RTPATH_MAX + 1]; … … 423 429 if (RT_FAILURE(rc)) 424 430 { 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); 426 432 return rc; 427 433 } … … 486 492 /** @todo sticy bits++ */ 487 493 488 if (! fLong)489 { 490 if ( fParseable)494 if (!(uFlags & VBOXSERVICETOOLBOXLSFLAG_LONG)) 495 { 496 if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) 491 497 { 492 498 /** @todo Skip node_id if not present/available! */ … … 499 505 cFileType, pNodeIt->dirEntry.cbName, pNodeIt->dirEntry.szName); 500 506 501 if ( fParseable) /* End of data block. */507 if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) /* End of data block. */ 502 508 RTPrintf("%c%c", 0, 0); 503 509 } 504 510 else 505 511 { 506 if ( fParseable)512 if (uFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) 507 513 { 508 514 RTPrintf("ftype=%c%c", cFileType, 0); … … 609 615 610 616 /* 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)) 612 619 { 613 620 /* Process all sub-directories. */ … … 618 625 switch (fMode & RTFS_TYPE_MASK) 619 626 { 620 //case RTFS_TYPE_SYMLINK: 627 case RTFS_TYPE_SYMLINK: 628 if (!(uFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS)) 629 break; 630 /* Fall through is intentional. */ 621 631 case RTFS_TYPE_DIRECTORY: 622 632 { … … 628 638 continue; 629 639 } 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); 632 646 } 633 647 break; … … 685 699 int rc = VINF_SUCCESS; 686 700 bool fVerbose = false; 687 bool fLong = false; 688 bool fMachineReadable = false; 689 bool fRecursive = false; 701 uint32_t fFlags = 0; 690 702 691 703 /* Init file list. */ … … 704 716 705 717 case 'l': /* Print long format. */ 706 f Long = true;718 fFlags |= VBOXSERVICETOOLBOXLSFLAG_LONG; 707 719 break; 708 720 709 721 case LS_OPT_MACHINE_READABLE: 710 f MachineReadable = true;722 fFlags |= VBOXSERVICETOOLBOXLSFLAG_PARSEABLE; 711 723 break; 712 724 713 725 case 'R': /* Recursive processing. */ 714 f Recursive = true;726 fFlags |= VBOXSERVICETOOLBOXLSFLAG_RECURSIVE; 715 727 break; 716 728 … … 758 770 759 771 /* Print magic/version. */ 760 if (f MachineReadable)772 if (fFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) 761 773 RTPrintf("hdr_id=vbt_ls%chdr_ver=%u%c", 0, 1 /* Version 1 */, 0); 762 774 … … 764 776 RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node) 765 777 { 766 rc = VBoxServiceToolboxLsOutput(pNodeIt->pszName, 767 fRecursive, fLong, fMachineReadable); 778 rc = VBoxServiceToolboxLsOutput(pNodeIt->pszName, fFlags); 768 779 if (RT_FAILURE(rc)) 769 780 RTMsgError("ls: Failed while enumerating directory '%s', rc=%Rrc\n", … … 771 782 } 772 783 773 if (f MachineReadable) /* Output termination. */784 if (fFlags & VBOXSERVICETOOLBOXLSFLAG_PARSEABLE) /* Output termination. */ 774 785 RTPrintf("%c%c%c%c", 0, 0, 0, 0); 775 786 }
Note:
See TracChangeset
for help on using the changeset viewer.