comparison mxtool/mx.py @ 19804:ad32fd810c83

mx: Support systems where SC_ARG_MAX has not defined limit
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Thu, 12 Mar 2015 12:45:04 +0100
parents 258b3658845a
children e87d55dfbbbb
comparison
equal deleted inserted replaced
19803:17cbf6870ca7 19804:ad32fd810c83
2804 if not exists(dirname(dst)): 2804 if not exists(dirname(dst)):
2805 os.makedirs(dirname(dst)) 2805 os.makedirs(dirname(dst))
2806 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)): 2806 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)):
2807 shutil.copyfile(src, dst) 2807 shutil.copyfile(src, dst)
2808 2808
2809 def _chunk_files_for_command_line(files, limit=None, pathFunction=None): 2809 def _chunk_files_for_command_line(files, limit=None, pathFunction=lambda f: f):
2810 """ 2810 """
2811 Returns a generator for splitting up a list of files into chunks such that the 2811 Returns a generator for splitting up a list of files into chunks such that the
2812 size of the space separated file paths in a chunk is less than a given limit. 2812 size of the space separated file paths in a chunk is less than a given limit.
2813 This is used to work around system command line length limits. 2813 This is used to work around system command line length limits.
2814 """ 2814 """
2822 limit = 32768 - commandLinePrefixAllowance 2822 limit = 32768 - commandLinePrefixAllowance
2823 else: 2823 else:
2824 # Using just SC_ARG_MAX without extra downwards adjustment 2824 # Using just SC_ARG_MAX without extra downwards adjustment
2825 # results in "[Errno 7] Argument list too long" on MacOS. 2825 # results in "[Errno 7] Argument list too long" on MacOS.
2826 syslimit = os.sysconf('SC_ARG_MAX') - 20000 2826 syslimit = os.sysconf('SC_ARG_MAX') - 20000
2827 if syslimit == -1:
2828 syslimit = 262144 # we could use sys.maxint but we prefer a more robust smaller value
2827 limit = syslimit - commandLinePrefixAllowance 2829 limit = syslimit - commandLinePrefixAllowance
2828 for i in range(len(files)): 2830 for i in range(len(files)):
2829 path = files[i] if pathFunction is None else pathFunction(files[i]) 2831 path = pathFunction(files[i])
2830 size = len(path) + 1 2832 size = len(path) + 1
2831 if chunkSize + size < limit: 2833 if chunkSize + size < limit:
2832 chunkSize += size 2834 chunkSize += size
2833 else: 2835 else:
2834 assert i > chunkStart 2836 assert i > chunkStart