Skip to content

Commit

Permalink
add tar.xz support
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Jun 20, 2024
1 parent 825bf11 commit 845b72d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,34 @@ Example: `'"name not like "z%"'`, `'"date not between "2010" and "2011-01-15"'`,

The following file properties are available:

| name | description |
|-------------|----------------------------------------------------------------|
| name | name of the file |
| path | full path of the file |
| container | path of the container (if inside an archive) |
| size | file size (uncompressed) |
| date | modified date in YYYY-MM-DD format |
| time | modified time in HH-MM-SS format |
| ext | short file extension (e.g., `txt`) |
| ext2 | long file extension (two parts, e.g., `tar.gz`) |
| type | `file`, `dir`, or `link` |
| archive | archive type: `tar`, `zip`, `7z`, `rar` or empty |
| name | description |
|-------------|-------------------------------------------------------------------|
| name | name of the file |
| path | full path of the file |
| container | path of the container (if inside an archive) |
| size | file size (uncompressed) |
| date | modified date in YYYY-MM-DD format |
| time | modified time in HH-MM-SS format |
| ext | short file extension (e.g., `txt`) |
| ext2 | long file extension (two parts, e.g., `tar.gz`) |
| type | `file`, `dir`, or `link` |
| archive | archive type: `tar`, `zip`, `7z`, `rar` or empty |

Helper properties

| name | description |
|-------------|----------------------------------------------------------------|
| today | today's date |
| name | description |
|-------------|-------------------------------------------------------------------|
| today | today's date |


## Supported archives

| name | extensions |
|-------------|----------------------------------------------------------------|
| tar | `.tar`, `.tar.gz`, `.tgz`, `.tar.bz2`, `.tbz2` |
| zip | `.zip` |
| 7zip | `.7z` |
| rar | `.rar` |
| name | extensions |
|-------------|-------------------------------------------------------------------|
| tar | `.tar`, `.tar.gz`, `.tgz`, `.tar.bz2`, `.tbz2`, `.tar.xz`, `.txz` |
| zip | `.zip` |
| 7zip | `.7z` |
| rar | `.rar` |

> Note: use the flag -n (or --no-archive) to disable archive support. You can also use `'not archive'` in your query but this still requires zfind to open the archive.
Expand Down
8 changes: 7 additions & 1 deletion find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/bodgit/sevenzip"
"github.com/laktak/zfind/filter"
"github.com/nwaples/rardecode"
"github.com/ulikunitz/xz"
)

// FileInfo is a type that represents information about a file or directory.
Expand Down Expand Up @@ -132,6 +133,10 @@ func listFilesInTar(fullpath string) ([]FileInfo, error) {
}
case strings.HasSuffix(fullpath, ".bz2") || strings.HasSuffix(fullpath, ".tbz2"):
fr = bzip2.NewReader(f)
case strings.HasSuffix(fullpath, ".xz") || strings.HasSuffix(fullpath, ".txz"):
if fr, err = xz.NewReader(f); err != nil {
return nil, &FindError{Path: fullpath, Err: err}
}
}

r := tar.NewReader(fr)
Expand Down Expand Up @@ -290,7 +295,8 @@ func findIn(param WalkParams, fi FileInfo) {

if strings.HasSuffix(fullpath, ".tar") ||
strings.HasSuffix(fullpath, ".tar.gz") || strings.HasSuffix(fullpath, ".tgz") ||
strings.HasSuffix(fullpath, ".tar.bz2") || strings.HasSuffix(fullpath, ".tbz2") {
strings.HasSuffix(fullpath, ".tar.bz2") || strings.HasSuffix(fullpath, ".tbz2") ||
strings.HasSuffix(fullpath, ".tar.xz") || strings.HasSuffix(fullpath, ".txz") {
files, err = listFilesInTar(fullpath)
} else if strings.HasSuffix(fullpath, ".zip") {
files, err = listFilesInZip(fullpath)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/bodgit/sevenzip v1.5.1
github.com/fatih/color v1.17.0
github.com/nwaples/rardecode v1.1.3
github.com/ulikunitz/xz v0.5.12
)

require (
Expand All @@ -21,7 +22,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions scripts/run_test_prep
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ cd $root/root/thing
tar -cvf ../way/thing.tar *
tar -czvf ../year/thing.tar.gz *
tar -czvf ../year/thing.tgz *
tar -cjvf ../people/thing.tar.bz2 *
tar -cjvf ../people/thing.tbz2 *
tar --bzip2 -cvf ../people/thing.tar.bz2 *
tar --bzip2 -cvf ../people/thing.tbz2 *
tar --xz -cvf ../people/thing.tar.xz *
tar --xz -cvf ../people/thing.txz *
rm -rf $root/root/thing

cd $root/root
Expand Down
2 changes: 2 additions & 0 deletions scripts/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function zft {
shift
local path=$1
shift
echo "- $name"
cd $root/$path
"$base_dir/zfind" "$@" > "$dir/$name.txt"
}
Expand All @@ -41,6 +42,7 @@ zft csv01 day/car 'type!="dir"' --csv

zft link01 / 'name like "party-%" and type="file"'
zft link02 / 'name like "party-%" and type="file"' -L
zft link03 / 'container like "%.tar.xz" and archive="tar" and name ilike "Art-%"' -L

zft arc01 day --archive-separator=": " 'path like "life/%" and archive="zip"'

Expand Down
2 changes: 2 additions & 0 deletions testdata/run_test/link02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ day/friend/party-result.png
people/face/party-result.png
people/history/party-result.png
people/thing.tar.bz2//body/history/party-result.mp4
people/thing.tar.xz//body/history/party-result.mp4
people/thing.tbz2//body/history/party-result.mp4
people/thing.txz//body/history/party-result.mp4
way/thing.tar//body/history/party-result.mp4
year/thing.tar.gz//body/history/party-result.mp4
year/thing.tgz//body/history/party-result.mp4
1 change: 1 addition & 0 deletions testdata/run_test/link03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
people/thing.tar.xz//body/art-war.png

0 comments on commit 845b72d

Please sign in to comment.