From 2f3a764de2e12103cbb9c1fab43b67deaa5623df Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 11 Oct 2024 00:03:55 +0100 Subject: command-line-tool: Compute hash of stdout file. * ravanan/command-line-tool.scm (build-command-line-tool-script)[path+sha1->value]: New function. [path->value]: Implement in terms of path+sha1->value. [stdout-output->value]: Use path+sha1->value. --- ravanan/command-line-tool.scm | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm index db2e45b..f2aec4a 100644 --- a/ravanan/command-line-tool.scm +++ b/ravanan/command-line-tool.scm @@ -820,10 +820,11 @@ directory of the workflow." path) secondary-file-value))) - (define (path->value path workflow-output-directory maybe-secondary-files) + (define (path+sha1->value path sha1 workflow-output-directory maybe-secondary-files) (maybe-assoc-set (copy-file-value (canonicalize-file-value `(("class" . "File") - ("path" . ,path))) + ("path" . ,path) + ("checksum" . ,(string-append "sha1$" sha1)))) workflow-output-directory) (cons "secondaryFiles" (maybe-let* ((secondary-files maybe-secondary-files)) @@ -833,26 +834,35 @@ directory of the workflow." workflow-output-directory) secondary-files)))))) + (define (path->value path workflow-output-directory maybe-secondary-files) + (path+sha1->value path + (sha1-hash path) + workflow-output-directory + maybe-secondary-files)) + (define (stdout-output->value workflow-output-directory stdout-directory stdout-filename output) (cons (assoc-ref output "id") - (path->value - (if (string=? stdout-filename - (file-name-join* stdout-directory "stdout")) - ;; If stdout filename is unspecified, rename it to a - ;; hash of its contents. - (let ((hashed-filename - (file-name-join* stdout-directory - (sha1-hash stdout-filename)))) - (rename-file stdout-filename - hashed-filename) - hashed-filename) - ;; Else, return the stdout filename as it is. - stdout-filename) - workflow-output-directory - %nothing))) + (let ((sha1 (sha1-hash stdout-filename))) + ;; Use path+sha1->value instead of path->value to avoid + ;; recomputing the SHA1 hash. + (path+sha1->value + (if (string=? stdout-filename + (file-name-join* stdout-directory "stdout")) + ;; If stdout filename is unspecified, rename it to a + ;; hash of its contents. + (let ((hashed-filename + (file-name-join* stdout-directory sha1))) + (rename-file stdout-filename + hashed-filename) + hashed-filename) + ;; Else, return the stdout filename as it is. + stdout-filename) + sha1 + workflow-output-directory + %nothing)))) (define (other-output->value workflow-output-directory output-id output-type-tree -- cgit v1.2.3