bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 58.


From: Collin Funk
Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 58.
Date: Fri, 15 Mar 2024 07:07:24 -0700
User-agent: Mozilla Thunderbird

This patch implements --hardlink and --local-hardlink. It is a larger
patch so feel free to ask questions or let me know if I missed
anything.

Most of the changes are just following the referenced commit.

Outside of that, I noticed a bug when testing hard links. After
running gnulib-tool.py --import --hardlink module there was many files
with the name *.tmp suffix. I'm not sure if there was a patch that
changed the behavior or if it was a bug in the gnulib-tool.py
implementation. In any case, I solved this in
GLFileAssistant.add_or_update along with adding some comments taken
from gnulib-tool.sh.

I used the following script for testing:

gnulib-tool.py --hardlink --create-testdir --dir test-python readme-release
gnulib-tool.sh --hardlink --create-testdir --dir test-shell readme-release
(cd test-python && gnulib-tool.py -s --hardlink --symlink -h --import fts)
(cd test-shell && gnulib-tool.sh -s --hardlink --symlink -h --import fts)
git diff --no-index test-python test-shell

Notice the arguments '-s --hardlink --symlink -h'. I tried to make
sure gnulib-tool.py behaved similarly to gnulib-tool.sh in this case.

I beleive the correct behavior is to use the last option given so
'-h'. Which this seems to confirm:

$ stat lib/fts.c  | grep 'Links'
Device: 0,39    Inode: 4852546     Links: 1
$ ./run-tests.sh
$ stat lib/fts.c  | grep 'Links'
Device: 0,39    Inode: 4852546     Links: 3

It doesn't seem there is a good way to do this with Python's argparse,
though I may not have looked at the documentation hard enough [1]. I
ended up doing this which seems to work, though is not very pretty:

    # --symlink and --hardlink are mutually exclusive.
    # Use the last one given.
    if symlink and hardlink:
        optindex_table = {}
        options = list(reversed(sys.argv[1:]))
        options_count = len(options)
        for option in ['-s', '--symbolic', '--symlink', '-h', '--hardlink']:
            if option in options:
                optindex_table[option] = options_count - options.index(option)
        last_option = max(optindex_table, key=optindex_table.get)
        # Disable the option that is not the last one.
        if last_option in ['-s', '--symbolic', '--symlink']:
            hardlink = False
        else:  # last_option is --hardlink or equivalent.
            symlink = False

And something similar for the --local-* variants.

I think that covers all of the strange hackery for this patch.

[1] https://docs.python.org/3/library/argparse.html

Collin

Attachment: 0001-gnulib-tool.py-Follow-gnulib-tool-changes-part-58.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]