unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 49149@debbugs.gnu.org
Subject: [bug#49149] [PATCH 0/7] Add deb format for guix pack.
Date: Wed, 30 Jun 2021 14:16:42 -0400	[thread overview]
Message-ID: <877dib43qt.fsf@gmail.com> (raw)
In-Reply-To: <87wnqboedx.fsf_-_@gnu.org> ("Ludovic Courtès"'s message of "Wed, 30 Jun 2021 12:06:34 +0200")

Hey,

Ludovic Courtès <ludo@gnu.org> writes:

[...]

>>  (define (file-prefix? file1 file2)
>> -  "Return #t if FILE1 denotes the name of a file that is a parent of FILE2,
>> -where both FILE1 and FILE2 are absolute file name.  For example:
>> +  "Return #t if FILE1 denotes the name of a file that is a parent of FILE2.
>> +For example:
>>  
>>    (file-prefix? \"/gnu\" \"/gnu/store\")
>>    => #t
>> @@ -240,19 +241,41 @@ where both FILE1 and FILE2 are absolute file name.  For example:
>>    (file-prefix? \"/gn\" \"/gnu/store\")
>>    => #f
>>  "
>> -  (and (string-prefix? "/" file1)
>> -       (string-prefix? "/" file2)
>
> Doesn’t it have the effect that now:
>
>   (file-prefix? "gnu" "/gnu/store") => #t
>
> ?

Good catch.  That seems sub-optimal.  How about:

--8<---------------cut here---------------start------------->8---
modified   gnu/system/file-systems.scm
@@ -233,6 +233,8 @@
 
 (define (file-prefix? file1 file2)
   "Return #t if FILE1 denotes the name of a file that is a parent of FILE2.
+FILE1 and FILE2 must both be either absolute or relative, else #f is returned.
+
 For example:
 
   (file-prefix? \"/gnu\" \"/gnu/store\")
@@ -241,17 +243,24 @@ For example:
   (file-prefix? \"/gn\" \"/gnu/store\")
   => #f
 "
-  (let loop ((file1 (string-tokenize file1 %not-slash))
-             (file2 (string-tokenize file2 %not-slash)))
-    (match file1
-      (()
-       #t)
-      ((head1 tail1 ...)
-       (match file2
-         ((head2 tail2 ...)
-          (and (string=? head1 head2) (loop tail1 tail2)))
-         (()
-          #f))))))
+  (define (absolute? file)
+    (string-prefix? "/" file))
+
+  (if (or (every absolute? (list file1 file2))
+          (every (negate absolute?) (list file1 file2)))
+      (let loop ((file1 (string-tokenize file1 %not-slash))
+                 (file2 (string-tokenize file2 %not-slash)))
+        (match file1
+          (()
+           #t)
+          ((head1 tail1 ...)
+           (match file2
+             ((head2 tail2 ...)
+              (and (string=? head1 head2) (loop tail1 tail2)))
+             (()
+              #f)))))
+      ;; FILE1 and FILE2 are a mix of absolute and relative paths.
+      #f))
--8<---------------cut here---------------end--------------->8---
 
 (define (file-name-depth file-name)
   (length (string-tokenize file-name %not-slash)))

> I’d rather insist on absolute file names and preserve the initial
> semantics, to avoid bad surprises.

I agree that not changing the original semantics would be safest;
nevertheless, we're talking about an internal helper that isn't widely
use; its couple usages are easy to review (and deals with mount points
which seems safe to assume are exclusively using absolute paths).
Especially after the above fix :-).

>> +(define (reduce-directories file-names)
>> +  "Eliminate entries in FILE-NAMES that are children of other entries in
>> +FILE-NAMES.  This is for example useful when passing a list of files to GNU
>> +tar, which would otherwise descend into each directory passed and archive the
>> +duplicate files as hard links, which can be undesirable."
>> +  (let* ((file-names/sorted
>> +          ;; Ascending sort by file hierarchy depth, then by file name length.
>> +          (stable-sort (delete-duplicates file-names)
>> +                       (lambda (f1 f2)
>> +                         (let ((depth1 (file-name-depth f1))
>> +                               (depth2 (file-name-depth f2)))
>> +                           (if (= depth1 depth2)
>> +                               (string< f1 f2)
>> +                               (< depth1 depth2)))))))
>> +    (reverse (fold (lambda (file-name results)
>> +                     (if (find (cut file-prefix? <> file-name) results)
>> +                         results        ;parent found -- skipping
>> +                         (cons file-name results)))
>> +                   '()
>> +                   file-names/sorted))))
>
> Likewise, I suspect it doesn’t work as intended if there are relative
> file names in the list, no?

You can see it at work in the tests/file-systems test module; it reduces

(reduce-directories '("./opt/gnu/etc" "./opt/gnu/" "./opt/gnu/bin"
                        "./opt/gnu/lib/debug" "./opt/gnuism" "a/b/c"
                        "a/b/c"))

into '("./opt/gnu/" "./opt/gnuism" "a/b/c"), none of which are absolute
file names.

> Perhaps we could add an example to the docstring.  Also, the word
> “reduce” doesn’t appear in the docstring, which to me suggests
> suboptimal naming.  ;-)

That the word 'reduce' doesn't appear in the docstring was a conscious
effort of mine to not bore the reader with repeating the same terms, ah!
But naming is hard; I'm open to suggestions.

Maxim




  reply	other threads:[~2021-06-30 18:17 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21  6:10 [bug#49149] [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-21  6:11 ` [bug#49149] [PATCH 1/7] pack: Extract builder code from self-contained-tarball Maxim Cournoyer
2021-06-21  6:11   ` [bug#49149] [PATCH] tentatively reuse rlib for cargo-build-system Maxim Cournoyer
2021-06-21 20:28     ` Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 2/7] pack: Factorize base tar options Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 3/7] pack: Fix typo Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-21 18:11     ` Maxime Devos
2021-06-22 14:03       ` Maxim Cournoyer
2021-06-23 10:22         ` Maxime Devos
2021-06-24  4:40           ` [bug#49149] [PATCH v2 1/7] pack: Extract builder code from self-contained-tarball Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 2/7] pack: Factorize base tar options Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 3/7] pack: Fix typo Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-26  5:03               ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-30 10:13               ` Ludovic Courtès
2021-06-30 18:36                 ` Maxim Cournoyer
2021-07-01 13:26                   ` Ludovic Courtès
2021-07-04  3:21                     ` Maxim Cournoyer
2021-07-05 16:14                       ` Ludovic Courtès
2021-07-05 20:42                         ` Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 5/7] pack: Prevent duplicate files in tar archives Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 6/7] tests: pack: Fix compressor extension Maxim Cournoyer
2021-06-24  4:40             ` [bug#49149] [PATCH v2 7/7] pack: Add support for the deb format Maxim Cournoyer
2021-06-26 16:58               ` Maxime Devos
2021-06-29 19:20                 ` bug#49149: [PATCH 0/7] Add deb format for guix pack Maxim Cournoyer
2021-06-30 10:10               ` [bug#49149] " Ludovic Courtès
2021-06-24  4:44           ` [bug#49149] [PATCH 4/7] pack: Improve naming of the packs store file names Maxim Cournoyer
2021-06-23 21:16       ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Ludovic Courtès
2021-06-21  6:12   ` [bug#49149] [PATCH 5/7] pack: Prevent duplicate files in tar archives Maxim Cournoyer
2021-06-30 10:06     ` [bug#49149] [PATCH 0/7] Add deb format for guix pack Ludovic Courtès
2021-06-30 18:16       ` Maxim Cournoyer [this message]
2021-07-01 13:24         ` Ludovic Courtès
2021-06-21  6:12   ` [bug#49149] [PATCH 6/7] tests: pack: Fix compressor extension Maxim Cournoyer
2021-06-21  6:12   ` [bug#49149] [PATCH 7/7] pack: Add support for the deb format Maxim Cournoyer
2021-06-21 16:44 ` [bug#49149] Add deb format for guix pack jgart via Guix-patches via
2021-06-23 21:28 ` [bug#49149] [PATCH 0/7] " Ludovic Courtès
2021-06-29 17:49   ` Maxim Cournoyer
2021-06-30  9:15     ` Ludovic Courtès
2021-06-30 13:49       ` zimoun
2021-06-30 15:06         ` zimoun
2021-06-30 16:55           ` Maxim Cournoyer
2021-06-30 16:54         ` Maxim Cournoyer
2021-06-30 17:28         ` Maxim Cournoyer
2021-06-30 17:36           ` Maxim Cournoyer
2021-06-30 17:47           ` zimoun
2021-06-30 19:20             ` Maxim Cournoyer
2021-07-01 13:08               ` zimoun
2021-06-30 16:42       ` Maxim Cournoyer
2021-07-01 13:20         ` Ludovic Courtès
2021-07-01 13:52           ` zimoun
2021-07-05 16:17             ` 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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=877dib43qt.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=49149@debbugs.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).