VirtualBox

Ignore:
Timestamp:
Feb 23, 2022 12:48:02 PM (3 years ago)
Author:
vboxsync
Message:

Validation Kit/TxS: Implemented (local) copy file support for TxS. Useful for copying stuff around on guests. bugref:10195

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecService.cpp

    r93747 r93895  
    660660 * @returns true if valid, false if invalid.
    661661 * @param   pPktHdr             The packet being unpacked.
    662  * @param   pszArgName           The argument name.
     662 * @param   pszArgName          The argument name.
    663663 * @param   psz                 Pointer to the string within pPktHdr.
    664664 * @param   ppszExp             Where to return the expanded string.  Must be
     
    10071007
    10081008    RTStrFree(pszPath);
     1009    return rc;
     1010}
     1011
     1012/**
     1013 * Copies a file from the source to the destination locally.
     1014 *
     1015 * @returns IPRT status code from send.
     1016 * @param   pPktHdr             The copy file packet.
     1017 */
     1018static int txsDoCopyFile(PCTXSPKTHDR pPktHdr)
     1019{
     1020    /* After the packet header follows a 32-bit file mode,
     1021     * the remainder of the packet are two zero terminated paths. */
     1022    size_t const cbMin = sizeof(TXSPKTHDR) + sizeof(RTFMODE) + 2;
     1023    if (pPktHdr->cb < cbMin)
     1024        return txsReplyBadMinSize(pPktHdr, cbMin);
     1025
     1026    RTFMODE const fMode = *(RTFMODE const *)(pPktHdr + 1);
     1027
     1028    int rc;
     1029
     1030    char       *pszSrc;
     1031    const char *pch;
     1032    if (txsIsStringValid(pPktHdr, "source", (const char *)(pPktHdr + 1) + sizeof(uint32_t) * 2, &pszSrc, &pch, &rc))
     1033    {
     1034        char *pszDst;
     1035        if (txsIsStringValid(pPktHdr, "dest", pch, &pszDst, NULL /* Check for string termination */, &rc))
     1036        {
     1037            rc = RTFileCopy(pszSrc, pszDst);
     1038            if (RT_SUCCESS(rc))
     1039            {
     1040                if (fMode) /* Do we need to set the file mode? */
     1041                {
     1042                    rc = RTPathSetMode(pszDst, fMode);
     1043                    if (RT_FAILURE(rc))
     1044                        rc = txsReplyRC(pPktHdr, rc, "RTPathSetMode(\"%s\", %#x)", pszDst, fMode);
     1045                }
     1046
     1047                if (RT_SUCCESS(rc))
     1048                    rc = txsReplyAck(pPktHdr);
     1049            }
     1050            else
     1051                rc = txsReplyRC(pPktHdr, rc, "RTFileCopy");
     1052            RTStrFree(pszDst);
     1053        }
     1054
     1055        RTStrFree(pszSrc);
     1056    }
     1057
    10091058    return rc;
    10101059}
     
    31053154        else if (txsIsSameOpcode(pPktHdr, "LIST    "))
    31063155            rc = txsDoList(pPktHdr);
     3156        else if (txsIsSameOpcode(pPktHdr, "CPFILE  "))
     3157            rc = txsDoCopyFile(pPktHdr);
    31073158        else if (txsIsSameOpcode(pPktHdr, "PUT FILE"))
    31083159            rc = txsDoPutFile(pPktHdr, false /*fHasMode*/);
     
    39734024    return rcExit;
    39744025}
    3975 
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