Closed mkitti closed 6 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
6269b5b
) 97.28% compared to head (17a81a3
) 97.55%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@nhz2 's implementation looks good as well: https://gist.github.com/nhz2/2db880497293868178225a964c68fd99#file-find-symlinks-jl-L12-L19
This feels like it could be implemented externally since it's quite a simple application of Tar.list
. In the calling code it would simply be this:
has_symlink = false
Tar.list(tarball) do hdr
has_symlink |= hdr.type == :symlink
end
If anything, I'd be inclined to add a generic predicate checker like this:
Tar.check_any(predicate::Function, tarball::ArgRead)
That checks if any entry in the tarball satsifies a predicate; it could be specialized with a type::Symbol
that would check if any of the entries in the tarball are of that type.
How would one write a function without getting into the non-public details of the header structure?
If islink
worked, Tar.list(islink, mytar.tar)
I would consider it
Also I don't get the need to |
, or, the results together. What we actually need is short circuting. Once we found the first symlink, we're done.
The Header
struct is public and documented and part of several APIs, see https://github.com/JuliaIO/Tar.jl#tarheader
We could add short-circuiting as an optimization if we have a Tar.contains
function, but I'd consider that an implementation detail.
How about we define Base.islink(h::Header) = h.type == :symlink
?
Here is the API I am imagining.
julia> open(GzipDecompressorStream, "P4est.v2.8.1.x86_64-w64-mingw32-mpi+microsoftmpi.tar.gz") do io
findfirst(islink, Tar.list(io)) != nothing
end
true
julia> Tar.create(mkdir("empty"), "foo.tar")
"foo.tar"
julia> findfirst(islink, Tar.list("foo.tar")) != nothing
false
For the short-circuiting what I really want is a lazy iterator over the headers rather than the eager Vector{Header}
from Tar.list
.
I've made a PR for the predicates on Header types: https://github.com/JuliaIO/Tar.jl/pull/169/files. Making an iterable object that does what iterate_headers
does seems quite annoying. The alternative would be to use the callback interface and raise an exception to terminate early; ugly but would avoid needing an iterator. In the mean time, I think that doing any(islink, Tar.list(tarball))
is fine.
Please also note that none of this is going to help the Pkg situation since I don't think we want to add faetures to Tar in a point release and a point release is what is where this issue is going to be fixed.
Implement
Tar.has_symlink
as requested by @staticfloatxref: https://github.com/JuliaLang/Pkg.jl/issues/3643#issuecomment-1880111897