VirtualBox

Changeset 62025 in vbox for trunk


Ignore:
Timestamp:
Jul 5, 2016 1:50:26 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
108487
Message:

ValidationKit,common: Wrapped shutil.copyfile in common/utils.py as copyFileSimple, applying the buffer hack before calling it.

Location:
trunk/src/VBox/ValidationKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r61988 r62025  
    378378             time.strftime('%Y-%m-%d %H:%M', time.localtime(oStat.st_mtime)), );
    379379
     380## Good buffer for file operations.
     381g_cbGoodBufferSize = 256*1024;
     382
     383## The original shutil.copyfileobj.
     384g_fnOriginalShCopyFileObj = None;
     385
     386def __myshutilcopyfileobj(fsrc, fdst, length = g_cbGoodBufferSize):
     387    """ shutil.copyfileobj with different length default value (16384 is slow with python 2.7 on windows). """
     388    return g_fnOriginalShCopyFileObj(fsrc, fdst, length);
     389
     390def __installShUtilHacks(shutil):
     391    """ Installs the shutil buffer size hacks. """
     392    global g_fnOriginalShCopyFileObj;
     393    if g_fnOriginalShCopyFileObj is None:
     394        g_fnOriginalShCopyFileObj = shutil.copyfileobj;
     395        shutil.copyfileobj = __myshutilcopyfileobj;
     396    return True;
     397
     398
     399def copyFileSimple(sFileSrc, sFileDst):
     400    """
     401    Wrapper around shutil.copyfile that simply copies the data of a regular file.
     402    Raises exception on failure.
     403    Return True for show.
     404    """
     405    import shutil;
     406    __installShUtilHacks(shutil);
     407    return shutil.copyfile(sFileSrc, sFileDst);
    380408
    381409#
     
    15591587
    15601588
    1561 ## Good buffer for file operations.
    1562 g_cbGoodBufferSize = 256*1024;
    1563 
    1564 ## The original shutil.copyfileobj.
    1565 g_fnOriginalShCopyFileObj = None;
    1566 
    1567 def __myshutilcopyfileobj(fsrc, fdst, length = g_cbGoodBufferSize):
    1568     """ shutil.copyfileobj with different length default value (16384 is slow with python 2.7 on windows). """
    1569     return g_fnOriginalShCopyFileObj(fsrc, fdst, length);
    1570 
    15711589## Set if we've replaced tarfile.copyfileobj with __mytarfilecopyfileobj already.
    15721590g_fTarCopyFileObjOverriddend = False;
     
    16081626    #
    16091627    if True is True:
    1610         global g_fnOriginalShCopyFileObj;
    1611         if g_fnOriginalShCopyFileObj is None:
    1612             g_fnOriginalShCopyFileObj = shutil.copyfileobj;
    1613             shutil.copyfileobj = __myshutilcopyfileobj;
     1628        __installShUtilHacks(shutil);
    16141629        global g_fTarCopyFileObjOverriddend;
    16151630        if g_fTarCopyFileObjOverriddend is False:
  • trunk/src/VBox/ValidationKit/common/webutils.py

    r61834 r62025  
    3131# Standard Python imports.
    3232import os;
    33 import shutil;
    3433import sys;
    3534import unittest;
     
    177176        fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile));
    178177        try:
    179             shutil.copyfile(sSrcPath, sDstFile);
     178            utils.copyFileSimple(sSrcPath, sDstFile);
    180179        except Exception, oXcpt:
    181180            fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt));
  • trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py

    r61840 r62025  
    3636import re
    3737import subprocess
    38 import shutil
    3938
    4039
     
    515514        reporter.log('_hardenedCopyFile: %s -> %s (mode: %o)' % (sSrc, sDst, iMode,));
    516515        if utils.getHostOs() in [ 'win', 'os2' ]:
    517             shutil.copyfile(sSrc, sDst);
     516            utils.copyFileSimple(sSrc, sDst);
    518517            os.chmod(sDst, iMode);
    519518        else:
Note: See TracChangeset for help on using the changeset viewer.

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