VirtualBox

Changeset 79447 in vbox


Ignore:
Timestamp:
Jul 1, 2019 3:48:27 PM (5 years ago)
Author:
vboxsync
Message:

ValKit/txsclient.py: Added chmod, chown and optional mode mask to the upload methods to better handle unix guests. bugref:9151

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/txsclient.py

    r79245 r79447  
    365365                            abPayload.append(ord(ch))
    366366                    abPayload.append(0);
    367                 elif isinstance(o, long):
     367                elif isinstance(o, (long, int)):
    368368                    if o < 0 or o > 0xffffffff:
    369369                        reporter.fatal('sendMsg: uint32_t payload is out of range: %s' % (hex(o)));
     
    10051005        return rc;
    10061006
    1007     #def "CHMOD   "
    1008     #def "CHOWN   "
    1009     #def "CHGRP   "
     1007    def taskChMod(self, sRemotePath, fMode):
     1008        rc = self.sendMsg('CHMOD', (int(fMode), sRemotePath,));
     1009        if rc is True:
     1010            rc = self.recvAckLogged('CHMOD');
     1011        return rc;
     1012
     1013    def taskChOwn(self, sRemotePath, idUser, idGroup):
     1014        rc = self.sendMsg('CHOWN', (int(idUser), int(idGroup), sRemotePath,));
     1015        if rc is True:
     1016            rc = self.recvAckLogged('CHOWN');
     1017        return rc;
    10101018
    10111019    def taskIsDir(self, sRemoteDir):
     
    10311039    #def "LIST    "
    10321040
    1033     def taskUploadFile(self, sLocalFile, sRemoteFile):
     1041    def taskUploadFile(self, sLocalFile, sRemoteFile, fMode, fFallbackOkay):
    10341042        #
    10351043        # Open the local file (make sure it exist before bothering TXS) and
     
    10431051
    10441052        # Common cause with taskUploadStr
    1045         rc = self.taskUploadCommon(oLocalFile, sRemoteFile);
     1053        rc = self.taskUploadCommon(oLocalFile, sRemoteFile, fMode, fFallbackOkay);
    10461054
    10471055        # Cleanup.
     
    10491057        return rc;
    10501058
    1051     def taskUploadString(self, sContent, sRemoteFile):
     1059    def taskUploadString(self, sContent, sRemoteFile, fMode, fFallbackOkay):
    10521060        # Wrap sContent in a file like class.
    10531061        class InStringFile(object): # pylint: disable=too-few-public-methods
     
    10681076
    10691077        oLocalString = InStringFile(sContent);
    1070         return self.taskUploadCommon(oLocalString, sRemoteFile);
    1071 
    1072     def taskUploadCommon(self, oLocalFile, sRemoteFile):
     1078        return self.taskUploadCommon(oLocalString, sRemoteFile, fMode, fFallbackOkay);
     1079
     1080    def taskUploadCommon(self, oLocalFile, sRemoteFile, fMode, fFallbackOkay):
    10731081        """Common worker used by taskUploadFile and taskUploadString."""
     1082        #
    10741083        # Command + ACK.
    1075         rc = self.sendMsg('PUT FILE', (sRemoteFile,));
    1076         if rc is True:
    1077             rc = self.recvAckLogged('PUT FILE');
     1084        #
     1085        # Only used the new PUT2FILE command if we've got a non-zero mode mask.
     1086        # Fall back on the old command if the new one is not known by the TXS.
     1087        #
     1088        if fMode == 0:
     1089            rc = self.sendMsg('PUT FILE', (sRemoteFile,));
     1090            if rc is True:
     1091                rc = self.recvAckLogged('PUT FILE');
     1092        else:
     1093            rc = self.sendMsg('PUT2FILE', (fMode, sRemoteFile));
     1094            if rc is True:
     1095                rc = self.recvAck();
     1096                if rc is False:
     1097                    reporter.maybeErr(self.fErr, 'recvAckLogged: PUT2FILE transport error');
     1098                elif rc is not True:
     1099                    if rc[0] == 'UNKNOWN' and fFallbackOkay:
     1100                        # Fallback:
     1101                        rc = self.sendMsg('PUT FILE', (sRemoteFile,));
     1102                        if rc is True:
     1103                            rc = self.recvAckLogged('PUT FILE');
     1104                    else:
     1105                        reporter.maybeErr(self.fErr, 'recvAckLogged: PUT2FILE response was %s: %s' % (rc[0], rc[1],));
     1106                        rc = False;
    10781107        if rc is True:
    10791108            #
     
    15161545        return self.asyncToSync(self.asyncRmTree, sRemoteTree, cMsTimeout, fIgnoreErrors);
    15171546
    1518     #def "CHMOD   "
    1519     #def "CHOWN   "
    1520     #def "CHGRP   "
     1547    def asyncChMod(self, sRemotePath, fMode, cMsTimeout = 30000, fIgnoreErrors = False):
     1548        """
     1549        Initiates a chmod task.
     1550
     1551        Returns True on success, False on failure (logged).
     1552
     1553        The task returns True on success, False on failure (logged).
     1554        """
     1555        return self.startTask(cMsTimeout, fIgnoreErrors, "chMod", self.taskChMod, (sRemotePath, fMode));
     1556
     1557    def syncChMod(self, sRemotePath, fMode, cMsTimeout = 30000, fIgnoreErrors = False):
     1558        """Synchronous version."""
     1559        return self.asyncToSync(self.asyncChMod, sRemotePath, fMode, cMsTimeout, fIgnoreErrors);
     1560
     1561    def asyncChOwn(self, sRemotePath, idUser, idGroup, cMsTimeout = 30000, fIgnoreErrors = False):
     1562        """
     1563        Initiates a chown task.
     1564
     1565        Returns True on success, False on failure (logged).
     1566
     1567        The task returns True on success, False on failure (logged).
     1568        """
     1569        return self.startTask(cMsTimeout, fIgnoreErrors, "chOwn", self.taskChOwn, (sRemotePath, idUser, idGroup));
     1570
     1571    def syncChOwn(self, sRemotePath, idUser, idGroup, cMsTimeout = 30000, fIgnoreErrors = False):
     1572        """Synchronous version."""
     1573        return self.asyncToSync(self.asyncChMod, sRemotePath, idUser, idGroup, cMsTimeout, fIgnoreErrors);
    15211574
    15221575    def asyncIsDir(self, sRemoteDir, cMsTimeout = 30000, fIgnoreErrors = False):
     
    15691622    #def "LIST    "
    15701623
    1571     def asyncUploadFile(self, sLocalFile, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
     1624    def asyncUploadFile(self, sLocalFile, sRemoteFile,
     1625                        fMode = 0, fFallbackOkay = True, cMsTimeout = 30000, fIgnoreErrors = False):
    15721626        """
    15731627        Initiates a download query task.
     
    15771631        The task returns True on success, False on failure (logged).
    15781632        """
    1579         return self.startTask(cMsTimeout, fIgnoreErrors, "upload", self.taskUploadFile, (sLocalFile, sRemoteFile));
    1580 
    1581     def syncUploadFile(self, sLocalFile, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
    1582         """Synchronous version."""
    1583         return self.asyncToSync(self.asyncUploadFile, sLocalFile, sRemoteFile, cMsTimeout, fIgnoreErrors);
    1584 
    1585     def asyncUploadString(self, sContent, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
     1633        return self.startTask(cMsTimeout, fIgnoreErrors, "upload",
     1634                              self.taskUploadFile, (sLocalFile, sRemoteFile, fMode, fFallbackOkay));
     1635
     1636    def syncUploadFile(self, sLocalFile, sRemoteFile, fMode = 0, fFallbackOkay = True, cMsTimeout = 30000, fIgnoreErrors = False):
     1637        """Synchronous version."""
     1638        return self.asyncToSync(self.asyncUploadFile, sLocalFile, sRemoteFile, fMode, fFallbackOkay, cMsTimeout, fIgnoreErrors);
     1639
     1640    def asyncUploadString(self, sContent, sRemoteFile,
     1641                          fMode = 0, fFallbackOkay = True, cMsTimeout = 30000, fIgnoreErrors = False):
    15861642        """
    15871643        Initiates a upload string task.
     
    15911647        The task returns True on success, False on failure (logged).
    15921648        """
    1593         return self.startTask(cMsTimeout, fIgnoreErrors, "uploadString", self.taskUploadString, (sContent, sRemoteFile));
    1594 
    1595     def syncUploadString(self, sContent, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
    1596         """Synchronous version."""
    1597         return self.asyncToSync(self.asyncUploadString, sContent, sRemoteFile, cMsTimeout, fIgnoreErrors);
     1649        return self.startTask(cMsTimeout, fIgnoreErrors, "uploadString",
     1650                              self.taskUploadString, (sContent, sRemoteFile, fMode, fFallbackOkay));
     1651
     1652    def syncUploadString(self, sContent, sRemoteFile, fMode = 0, fFallbackOkay = True, cMsTimeout = 30000, fIgnoreErrors = False):
     1653        """Synchronous version."""
     1654        return self.asyncToSync(self.asyncUploadString, sContent, sRemoteFile, fMode, fFallbackOkay, cMsTimeout, fIgnoreErrors);
    15981655
    15991656    def asyncDownloadFile(self, sRemoteFile, sLocalFile, cMsTimeout = 30000, fIgnoreErrors = False):
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