all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: [PATCH] union: Ensure that the output is always a directory
Date: Thu, 03 Apr 2014 18:04:51 -0400	[thread overview]
Message-ID: <87mwg2gjcs.fsf_-_@yeeloong.lan> (raw)
In-Reply-To: <87ha6anp8g.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Thu, 03 Apr 2014 22:15:59 +0200")

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]

ludo@gnu.org (Ludovic Courtès) writes:

> I stumbled upon this bug: building a profile with a single package
> fails, because the new union.scm makes the profile directory a symlink
> to that package, which then prevents the creation of the ‘manifest’
> file:

Indeed!  Here's a patch that fixes that problem.

   Thanks,
     Mark


[-- Attachment #2: [PATCH] union: Ensure that the output is always a directory --]
[-- Type: text/x-patch, Size: 3943 bytes --]

From 6c8582bc41c8935b8e9d63146595e87d9b92fa95 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Thu, 3 Apr 2014 17:49:20 -0400
Subject: [PATCH] union: Ensure that the output is always a directory.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes the creation of single-package profiles, reported by Ludovic Courtès.

* guix/build/union.scm (union-build): Add new internal procedure
  'union-of-directories' that always creates a directory, containing the code
  previously used only to merge multiple directories.  Call it from the
  multiple-directory case in 'union' and from the top-level 'union-build'.
---
 guix/build/union.scm | 53 +++++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/guix/build/union.scm b/guix/build/union.scm
index c65bea4..ccd2d5c 100644
--- a/guix/build/union.scm
+++ b/guix/build/union.scm
@@ -108,30 +108,8 @@ the INPUTS."
        (call-with-values (lambda () (partition file-is-directory? inputs))
          (match-lambda*
            ((dirs ())
-            ;; All inputs are directories.  Create a new directory
-            ;; where we will merge the input directories.
-            (mkdir output)
-
-            ;; Build a hash table mapping each file to a list of input
-            ;; directories containing that file.
-            (let ((table (make-hash-table)))
-
-              (define (add-to-table! file dir)
-                (hash-set! table file (cons dir (hash-ref table file '()))))
-
-              ;; Populate the table.
-              (for-each (lambda (dir)
-                          (for-each (cut add-to-table! <> dir)
-                                    (files-in-directory dir)))
-                        dirs)
-
-              ;; Now iterate over the table and recursively
-              ;; perform a union for each entry.
-              (hash-for-each (lambda (file dirs-with-file)
-                               (union (string-append output "/" file)
-                                      (map (cut string-append <> "/" file)
-                                           (reverse dirs-with-file))))
-                             table)))
+            ;; All inputs are directories.
+            (union-of-directories output dirs))
 
            ((() (file (? (cut file=? <> file)) ...))
             ;; There are no directories, and all files have the same contents,
@@ -141,11 +119,36 @@ the INPUTS."
            ((dirs files)
             (resolve-collisions output dirs files)))))))
 
+  (define (union-of-directories output dirs)
+    ;; Create a new directory where we will merge the input directories.
+    (mkdir output)
+
+    ;; Build a hash table mapping each file to a list of input
+    ;; directories containing that file.
+    (let ((table (make-hash-table)))
+
+      (define (add-to-table! file dir)
+        (hash-set! table file (cons dir (hash-ref table file '()))))
+
+      ;; Populate the table.
+      (for-each (lambda (dir)
+                  (for-each (cut add-to-table! <> dir)
+                            (files-in-directory dir)))
+                dirs)
+
+      ;; Now iterate over the table and recursively
+      ;; perform a union for each entry.
+      (hash-for-each (lambda (file dirs-with-file)
+                       (union (string-append output "/" file)
+                              (map (cut string-append <> "/" file)
+                                   (reverse dirs-with-file))))
+                     table)))
+
   (setvbuf (current-output-port) _IOLBF)
   (setvbuf (current-error-port) _IOLBF)
   (when (file-port? log-port)
     (setvbuf log-port _IOLBF))
 
-  (union output (delete-duplicates inputs)))
+  (union-of-directories output (delete-duplicates inputs)))
 
 ;;; union.scm ends here
-- 
1.8.4


  reply	other threads:[~2014-04-03 22:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-02 18:37 [PATCH] union: Rewrite to be faster; handle symlink/directory conflicts Mark H Weaver
2014-04-02 19:20 ` Ludovic Courtès
2014-04-03 20:15 ` Ludovic Courtès
2014-04-03 22:04   ` Mark H Weaver [this message]
2014-04-03 22:10     ` [PATCH] union: Ensure that the output is always a directory Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mwg2gjcs.fsf_-_@yeeloong.lan \
    --to=mhw@netris.org \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.