Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: Make %setup work with archives regardless of inner structure #2664

Closed
Conan-Kudo opened this issue Sep 13, 2023 · 10 comments
Closed

RFE: Make %setup work with archives regardless of inner structure #2664

Conan-Kudo opened this issue Sep 13, 2023 · 10 comments
Labels
handsfree Packaging automation and convenience RFE

Comments

@Conan-Kudo
Copy link
Member

Conan-Kudo commented Sep 13, 2023

In a conversation in #devel:fedoraproject.org with @penguinpee, I realized that there's a potential quality of life improvement we could look into making around %setup: Making it so we don't ever need to use -n.

It started with asking about how to pass in --strip-components=1 to %setup, and I realized something: now that libarchive exists, it would be possible for us to have a universal unarchiver program with RPM that can give us the ability to automatically handle extracting archives properly, regardless of what the name of the top level directory is or whether there is even one at all.

For some prior art, Debian's packaging tooling can do this, and it uses that to 1) extract the tarball into a name-version directory, and 2) blow away debian directory of an upstream tarball if it exists so its own version can be unpacked in-tree.

Obviously, we don't need to do the second thing, but the first thing would be extremely useful. Note that because of compatibility concerns, we'd probably want this new behavior in a new macro.

@pmatilai pmatilai added the RFE label Sep 14, 2023
@pmatilai pmatilai added this to RPM Sep 14, 2023
@github-project-automation github-project-automation bot moved this to Backlog in RPM Sep 14, 2023
@pmatilai pmatilai changed the title Make %setup work with archives regardless of inner structure RFE: Make %setup work with archives regardless of inner structure Sep 14, 2023
@pmatilai
Copy link
Member

Right, this closely relates to #2078 as well.

Libarchive is currently an optional dependency, but a hard dep wouldn't be the end of the world.

@Conan-Kudo
Copy link
Member Author

Note that because of compatibility concerns, we'd probably want this new behavior in a new macro.

We could make %autosetup use this behavior by default when -n isn't present, though. It's a "do-what-I-mean" change that would be beneficial for most.

@penguinpee
Copy link

We could make %autosetup use this behavior by default when -n isn't present, though. It's a "do-what-I-mean" change that would be beneficial for most.

That would bring it in line with the way %forgeautosetup behaves. I assume that would be beneficial to both.

@teknoraver
Copy link
Contributor

@Conan-Kudo how libarchive can help in detect if the archive needs to be extracted as is or in a subdirectory?
Is there a]is some function to detect it, or we need to inspect the archive to see if the root entry has just one entry?

@Conan-Kudo
Copy link
Member Author

I believe we have to inspect it to check.

@teknoraver
Copy link
Contributor

In simple words the logic will be: if the archive contains a single entry extract it as is, otherwise create an entry like $name-$version?

@Conan-Kudo
Copy link
Member Author

Not quite. If it contains a single entry, strip it. Always create the directory %name-%version and extract into it.

@teknoraver
Copy link
Contributor

I have a draft change in https://github.com/teknoraver/rpm/tree/libarchive2

Most of the work needed to be done in rpmuncompress, I added a -p flag which does the following:

$ tar vtf source-singleroot.tar.gz
drwxr-xr-x root/root         0 2024-01-16 19:13 source-xxxxxxxxxx/
-rw-r--r-- root/root        32 2024-01-16 19:13 source-xxxxxxxxxx/file1
-rw-r--r-- root/root     33886 2024-01-16 19:13 source-xxxxxxxxxx/file2
drwxr-xr-x root/root         0 2024-01-16 19:13 source-xxxxxxxxxx/dir1/
-r--r--r-- root/root       210 2024-01-16 19:13 source-xxxxxxxxxx/dir1/file3

$ tar vtf source-noroot.tar.gz
drwxr-xr-x root/root         0 2024-01-16 19:13 dir1/
-r--r--r-- root/root       210 2024-01-16 19:13 dir1/file3
-rw-r--r-- root/root        32 2024-01-16 19:13 file1
-rw-r--r-- root/root     33886 2024-01-16 19:13 file2

$ ll
total 28
-rw-r--r--. 1 teknoraver teknoraver 10324 Jan 16 19:14 source-noroot.tar.gz
-rw-r--r--. 1 teknoraver teknoraver 10520 Jan 16 19:14 source-singleroot.tar.gz
-rw-r--r--. 1 teknoraver teknoraver   649 Jan 15 20:54 test.spec

$ ~/rpm/usr/lib/rpm/rpmuncompress -x -v -p source-1.0.0 source-singleroot.tar.gz
mkdir 'source-1.0.0' ;  /usr/bin/gzip -dc  'source-singleroot.tar.gz' | /usr/bin/tar -xvvof -  -C 'source-1.0.0' --strip-components=1
-rw-r--r-- root/root        32 2024-01-16 19:13 source-xxxxxxxxxx/file1
-rw-r--r-- root/root     33886 2024-01-16 19:13 source-xxxxxxxxxx/file2
drwxr-xr-x root/root         0 2024-01-16 19:13 source-xxxxxxxxxx/dir1/
-r--r--r-- root/root       210 2024-01-16 19:13 source-xxxxxxxxxx/dir1/file3

$ find source-1.0.0 -ls
    92341      0 drwxr-xr-x   1 teknoraver teknoraver       28 Jan 16 19:16 source-1.0.0
    92342      4 -rw-r--r--   1 teknoraver teknoraver       32 Jan 16 19:13 source-1.0.0/file1
    92343     36 -rw-r--r--   1 teknoraver teknoraver    33886 Jan 16 19:13 source-1.0.0/file2
    92344      0 drwxr-xr-x   1 teknoraver teknoraver       10 Jan 16 19:13 source-1.0.0/dir1
    92345      4 -r--r--r--   1 teknoraver teknoraver      210 Jan 16 19:13 source-1.0.0/dir1/file3

$ ~/rpm/usr/lib/rpm/rpmuncompress -x -v -p source-2.0.0 source-noroot.tar.gz
mkdir 'source-2.0.0' ;  /usr/bin/gzip -dc  'source-noroot.tar.gz' | /usr/bin/tar -xvvof -  -C 'source-2.0.0'
drwxr-xr-x root/root         0 2024-01-16 19:13 dir1/
-r--r--r-- root/root       210 2024-01-16 19:13 dir1/file3
-rw-r--r-- root/root        32 2024-01-16 19:13 file1
-rw-r--r-- root/root     33886 2024-01-16 19:13 file2

$ find source-2.0.0 -ls
    92346      0 drwxr-xr-x   1 teknoraver teknoraver       28 Jan 16 19:17 source-2.0.0
    92347      0 drwxr-xr-x   1 teknoraver teknoraver       10 Jan 16 19:13 source-2.0.0/dir1
    92348      4 -r--r--r--   1 teknoraver teknoraver      210 Jan 16 19:13 source-2.0.0/dir1/file3
    92349      4 -rw-r--r--   1 teknoraver teknoraver       32 Jan 16 19:13 source-2.0.0/file1
    92350     36 -rw-r--r--   1 teknoraver teknoraver    33886 Jan 16 19:13 source-2.0.0/file2

@teknoraver
Copy link
Contributor

Done in #2859

@pmatilai
Copy link
Member

pmatilai commented Feb 2, 2024

Oh, yup, this can be closed now. Thanks again!

@pmatilai pmatilai closed this as completed Feb 2, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in RPM Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
handsfree Packaging automation and convenience RFE
Projects
Status: Done
Development

No branches or pull requests

4 participants