Bug 15471 - tar --exclude did not consider --strip-components
Summary: tar --exclude did not consider --strip-components
Status: RESOLVED INVALID
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-22 06:53 UTC by kkocdko
Modified: 2023-03-22 07:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kkocdko 2023-03-22 06:53:11 UTC
# tar --exclude did not consider --strip-components

While gnu tar extract a tar file with content `./dir1/dir2/file`, using `--strip-components 1 --exclude dir2` switches, it will first strip `dir1`, then match and exclude `dir2`.

However what busybox's tar implementation do is first to match and exclude, then do `--strip-components 1`.

The test.sh here:

```sh
# tested on debian:11 livecd and fedora:37 livecd
busybox

# clear old files
rm -rf bb-test

# prepair for testing
mkdir -p bb-test/dir1/dir2
cd bb-test
echo file3-content > dir1/dir2/file3
tar -cf a.tar ./dir1
mkdir out-coreut-1 out-busybo-1 out-coreut-2 out-busybo-2

# let's try!
        tar -xf a.tar -C out-coreut-1 --strip-components 1 --exclude dir1
busybox tar -xf a.tar -C out-busybo-1 --strip-components 1 --exclude dir1
        tar -xf a.tar -C out-coreut-2 --strip-components 1 --exclude dir2
busybox tar -xf a.tar -C out-busybo-2 --strip-components 1 --exclude dir2

# see difference
echo "" && tree out-coreut-1
echo "" && tree out-busybo-1
echo "" && tree out-coreut-2
echo "" && tree out-busybo-2

cd ..
```

And the output on my machine:

```
[kkocdko@klf busybox-report]$ ./test.sh
BusyBox v1.36.0 (2023-01-10 00:00:00 UTC) multi-call binary.
...

out-coreut-1

0 directories, 0 files

out-busybo-1
└── dir1
    └── dir2
        └── file3

3 directories, 1 file

out-coreut-2
└── dir1

2 directories, 0 files

out-busybo-2
└── dir1
    └── dir2
        └── file3

3 directories, 1 file
[kkocdko@klf busybox-report]$
```
Comment 1 kkocdko 2023-03-22 07:14:40 UTC
I'm sorry, the test script is broken.