~ruther/guix-local

133910fd65363eb1fb26aeabb48fa07434ee83c5 — Rutherther 6 months ago 231562b
inferior: cached-channel-instance: Recalculate key after fetching channels.

Fixes #3454.

Because the channels in the incoming argument do not have to include all
dependencies, it is possible a cache entry with wrong key is created.

Recalculate the key after obtaining all dependencies of channels
through latest-channel-instances.

* guix/inferior.scm (cached-channel-instance): Recalculate cached file
location from latest-channel-instances commits before caching.

Change-Id: I37da107520bf5abd89c92a5ce6d3e2fc399454c3
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
1 files changed, 9 insertions(+), 8 deletions(-)

M guix/inferior.scm
M guix/inferior.scm => guix/inferior.scm +9 -8
@@ 915,13 915,13 @@ X.509 host certificate; otherwise, warn about the problem and keep going."
                                #:verify-certificate? verify-certificate?))
         channels))

  (define key
  (define (key commits)
    (bytevector->base32-string
     (sha256
      (string->utf8 (string-concatenate commits)))))

  (define cached
    (string-append cache-directory "/" key))
  (define (cached commits)
    (string-append cache-directory "/" (key commits)))

  (define (base32-encoded-sha256? str)
    (= (string-length str) 52))


@@ 962,8 962,8 @@ X.509 host certificate; otherwise, warn about the problem and keep going."
                                      (file-expiration-time ttl))


  (if (file-exists? cached)
      cached
  (if (file-exists? (cached commits))
      (cached commits)
      (run-with-store store
        (mlet* %store-monad ((instances
                              -> (latest-channel-instances store channels


@@ 975,6 975,7 @@ X.509 host certificate; otherwise, warn about the problem and keep going."
                                                           validate-channels
                                                           #:verify-certificate?
                                                           verify-certificate?))
                             (commits -> (map channel-instance-commit instances))
                             (profile
                              (channel-instances->derivation instances)))
          (mbegin %store-monad


@@ 985,9 986,9 @@ X.509 host certificate; otherwise, warn about the problem and keep going."
            ;; Cache if and only if AUTHENTICATE? is true.
            (if authenticate?
                (mbegin %store-monad
                  (symlink* (derivation->output-path profile) cached)
                  (add-indirect-root* cached)
                  (return cached))
                  (symlink* (derivation->output-path profile) (cached commits))
                  (add-indirect-root* (cached commits))
                  (return (cached commits)))
                (mbegin %store-monad
                  (add-temp-root* (derivation->output-path profile))
                  (return (derivation->output-path profile)))))))))