diff options
| -rwxr-xr-x | scripts/combo-layer | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/scripts/combo-layer b/scripts/combo-layer index a0a737d6ee..1ca2ce6c02 100755 --- a/scripts/combo-layer +++ b/scripts/combo-layer | |||
| @@ -1266,8 +1266,35 @@ def apply_commit(parent, rev, largs, wargs, dest_dir, file_filter=None): | |||
| 1266 | target = os.path.join(wargs["destdir"], dest_dir) | 1266 | target = os.path.join(wargs["destdir"], dest_dir) |
| 1267 | if not os.path.isdir(target): | 1267 | if not os.path.isdir(target): |
| 1268 | os.makedirs(target) | 1268 | os.makedirs(target) |
| 1269 | runcmd("git archive %s %s | tar -C %s -xf -" % (rev, ' '.join([pipes.quote(x) for x in update]), pipes.quote(target)), **largs) | 1269 | quoted_target = pipes.quote(target) |
| 1270 | runcmd("git add -f".split() + [os.path.join(dest_dir, x) for x in update], **wargs) | 1270 | # os.sysconf('SC_ARG_MAX') is lying: running a command with |
| 1271 | # string length 629343 already failed with "Argument list too | ||
| 1272 | # long" although SC_ARG_MAX = 2097152. "man execve" explains | ||
| 1273 | # the limitations, but those are pretty complicated. So here | ||
| 1274 | # we just hard-code a fixed value which is more likely to work. | ||
| 1275 | max_cmdsize = 64 * 1024 | ||
| 1276 | while update: | ||
| 1277 | quoted_args = [] | ||
| 1278 | unquoted_args = [] | ||
| 1279 | cmdsize = 100 + len(quoted_target) | ||
| 1280 | while update: | ||
| 1281 | quoted_next = pipes.quote(update[0]) | ||
| 1282 | size_next = len(quoted_next) + len(dest_dir) + 1 | ||
| 1283 | logger.debug('cmdline length %d + %d < %d?' % (cmdsize, size_next, os.sysconf('SC_ARG_MAX'))) | ||
| 1284 | if cmdsize + size_next < max_cmdsize: | ||
| 1285 | quoted_args.append(quoted_next) | ||
| 1286 | unquoted_args.append(update.pop(0)) | ||
| 1287 | cmdsize += size_next | ||
| 1288 | else: | ||
| 1289 | logger.debug('Breaking the cmdline at length %d' % cmdsize) | ||
| 1290 | break | ||
| 1291 | logger.debug('Final cmdline length %d / %d' % (cmdsize, os.sysconf('SC_ARG_MAX'))) | ||
| 1292 | cmd = "git archive %s %s | tar -C %s -xf -" % (rev, ' '.join(quoted_args), quoted_target) | ||
| 1293 | logger.debug('First cmdline length %d' % len(cmd)) | ||
| 1294 | runcmd(cmd, **largs) | ||
| 1295 | cmd = "git add -f".split() + [os.path.join(dest_dir, x) for x in unquoted_args] | ||
| 1296 | logger.debug('Second cmdline length %d' % reduce(lambda x, y: x + len(y), cmd, 0)) | ||
| 1297 | runcmd(cmd, **wargs) | ||
| 1271 | if delete: | 1298 | if delete: |
| 1272 | for path in delete: | 1299 | for path in delete: |
| 1273 | if dest_dir: | 1300 | if dest_dir: |
