@@ -425,6 +425,10 @@ type mode =
425
425
; conf : conf
426
426
}
427
427
428
+ type status =
429
+ | Some_substitution
430
+ | No_substitution
431
+
428
432
(* * The copy algorithm works as follow:
429
433
430
434
{v
@@ -465,8 +469,7 @@ output the replacement | |
465
469
v} *)
466
470
let parse ~input ~mode =
467
471
let open Fiber.O in
468
- let rec loop scanner_state ~beginning_of_data ~pos ~end_of_data ~has_seen_subs
469
- =
472
+ let rec loop scanner_state ~beginning_of_data ~pos ~end_of_data ~status =
470
473
let scanner_state = Scanner. run scanner_state ~buf ~pos ~end_of_data in
471
474
let placeholder_start =
472
475
match scanner_state with
@@ -492,7 +495,7 @@ let parse ~input ~mode =
492
495
match decode placeholder with
493
496
| Some t -> (
494
497
match mode with
495
- | Test -> Fiber. return true
498
+ | Test -> Fiber. return Some_substitution
496
499
| Copy { output; input_file; conf } ->
497
500
let * s = eval t ~conf in
498
501
(if ! Clflags. debug_artifact_substitution then
@@ -509,13 +512,13 @@ let parse ~input ~mode =
509
512
output (Bytes. unsafe_of_string s) 0 len;
510
513
let pos = placeholder_start + len in
511
514
loop Scan0 ~beginning_of_data: pos ~pos ~end_of_data
512
- ~has_seen_subs: true )
515
+ ~status: Some_substitution )
513
516
| None ->
514
517
(* Restart just after [prefix] since we know for sure that a placeholder
515
518
cannot start before that. *)
516
519
loop Scan0 ~beginning_of_data: placeholder_start
517
520
~pos: (placeholder_start + prefix_len)
518
- ~end_of_data ~has_seen_subs )
521
+ ~end_of_data ~status )
519
522
| scanner_state -> (
520
523
(* We reached the end of the buffer: move the leftover data back to the
521
524
beginning of [buf] and refill the buffer *)
@@ -538,23 +541,24 @@ let parse ~input ~mode =
538
541
(* There might still be another placeholder after this invalid one
539
542
with a length that is too long *)
540
543
loop Scan0 ~beginning_of_data: 0 ~pos: prefix_len ~end_of_data: leftover
541
- ~has_seen_subs
544
+ ~status
542
545
| _ -> (
543
546
match mode with
544
- | Test -> Fiber. return false
547
+ | Test -> Fiber. return No_substitution
545
548
| Copy { output; _ } ->
546
549
(* Nothing more to read; [leftover] is definitely not the beginning
547
550
of a placeholder, send it and end the copy *)
548
551
output buf 0 leftover;
549
- Fiber. return has_seen_subs ))
552
+ Fiber. return status ))
550
553
| n ->
551
554
loop scanner_state ~beginning_of_data: 0 ~pos: leftover
552
- ~end_of_data: (leftover + n) ~has_seen_subs )
555
+ ~end_of_data: (leftover + n) ~status )
553
556
in
554
557
match input buf 0 buf_len with
555
- | 0 -> Fiber. return false
558
+ | 0 -> Fiber. return No_substitution
556
559
| n ->
557
- loop Scan0 ~beginning_of_data: 0 ~pos: 0 ~end_of_data: n ~has_seen_subs: false
560
+ loop Scan0 ~beginning_of_data: 0 ~pos: 0 ~end_of_data: n
561
+ ~status: No_substitution
558
562
559
563
let copy ~conf ~input_file ~input ~output =
560
564
parse ~input ~mode: (Copy { conf; input_file; output })
@@ -570,8 +574,8 @@ let copy_file_non_atomic ~conf ?chmod ~src ~dst () =
570
574
571
575
let run_sign_hook conf ~has_subst file =
572
576
match has_subst with
573
- | false -> Fiber. return ()
574
- | true -> (
577
+ | No_substitution -> Fiber. return ()
578
+ | Some_substitution -> (
575
579
match Lazy. force conf.sign_hook with
576
580
| Some hook -> hook file
577
581
| None -> Fiber. return () )
0 commit comments