|
4 | 4 | "pathlib", |
5 | 5 | "shutil", |
6 | 6 | "subprocess", |
| 7 | + "sys", |
7 | 8 | "_shared", |
8 | 9 | ] |
9 | 10 |
|
|
12 | 13 | import pathlib |
13 | 14 | import shutil |
14 | 15 | import subprocess |
| 16 | +import sys |
15 | 17 |
|
16 | 18 | import _shared |
17 | 19 |
|
@@ -376,45 +378,53 @@ def archive(context): |
376 | 378 | int(source_date_epoch), datetime.UTC |
377 | 379 | ).strftime(mtime_format) |
378 | 380 | else: |
379 | | - mtime = subprocess.run( |
| 381 | + try: |
| 382 | + mtime = subprocess.run( |
| 383 | + [ |
| 384 | + "git", |
| 385 | + "log", |
| 386 | + "-1", |
| 387 | + "--format=tformat:%cd", |
| 388 | + f"--date=format:{mtime_format}", |
| 389 | + os.fsdecode(context.checkout), |
| 390 | + ], |
| 391 | + env={"TZ": "UTC0"}, |
| 392 | + capture_output=True, |
| 393 | + text=True, |
| 394 | + check=True, |
| 395 | + ).stdout.strip() |
| 396 | + except subprocess.CalledProcessError as error: |
| 397 | + print(error.output) |
| 398 | + sys.exit(error.returncode) |
| 399 | + |
| 400 | + try: |
| 401 | + subprocess.run( |
380 | 402 | [ |
381 | | - "git", |
382 | | - "log", |
383 | | - "-1", |
384 | | - "--format=tformat:%cd", |
385 | | - f"--date=format:{mtime_format}", |
386 | | - os.fsdecode(context.checkout), |
| 403 | + "tar", |
| 404 | + "-c", |
| 405 | + "-f", |
| 406 | + os.fsdecode(file_path), |
| 407 | + "--sort=name", |
| 408 | + "--mtime", |
| 409 | + mtime, |
| 410 | + "--clamp-mtime", |
| 411 | + "--owner=0", |
| 412 | + "--group=0", |
| 413 | + "--numeric-owner", |
| 414 | + "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime", |
| 415 | + "--mode=go+u,go-w", |
| 416 | + # Explicitly using `-T` because if you don't compress with threads you can't |
| 417 | + # uncompress with them and the size difference is negligible when using |
| 418 | + # single-threaded compression. |
| 419 | + "--use-compress-program", |
| 420 | + "xz -T 0", |
| 421 | + to_compress.name, |
387 | 422 | ], |
388 | | - env={"TZ": "UTC0"}, |
| 423 | + cwd=to_compress.parent, |
389 | 424 | capture_output=True, |
390 | 425 | text=True, |
391 | 426 | check=True, |
392 | | - ).stdout.strip() |
393 | | - |
394 | | - subprocess.run( |
395 | | - [ |
396 | | - "tar", |
397 | | - "-c", |
398 | | - "-f", |
399 | | - os.fsdecode(file_path), |
400 | | - "--sort=name", |
401 | | - "--mtime", |
402 | | - mtime, |
403 | | - "--clamp-mtime", |
404 | | - "--owner=0", |
405 | | - "--group=0", |
406 | | - "--numeric-owner", |
407 | | - "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime", |
408 | | - "--mode=go+u,go-w", |
409 | | - # Explicitly using `-T` because if you don't compress with threads you can't |
410 | | - # uncompress with them and the size difference is negligible when using |
411 | | - # single-threaded compression. |
412 | | - "--use-compress-program", |
413 | | - "xz -T 0", |
414 | | - to_compress.name, |
415 | | - ], |
416 | | - cwd=to_compress.parent, |
417 | | - capture_output=True, |
418 | | - text=True, |
419 | | - check=True, |
420 | | - ) |
| 427 | + ) |
| 428 | + except subprocess.CalledProcessError as error: |
| 429 | + print(error.output) |
| 430 | + sys.exit(error.returncode) |
0 commit comments