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

Silence 7zip when unpacking #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/post_fetch_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ function unpack_cmd(file,directory,extension,secondary_extension)
p7zip() do exe7z
if secondary_extension == ".tar" || extension == ".tgz" || extension == ".tbz"
# special handling for compressed tarballs
return pipeline(`$exe7z x $file -y -so`, `$exe7z x -si -y -ttar -o$directory`)
return pipeline(`$exe7z x $file -y -so`, `$exe7z x -si -y -ttar -o$directory -bso0 -bsp0`)
else
return `$exe7z x $file -y -o$directory`
return `$exe7z x $file -y -o$directory -bso0 -bsp0`
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/assets/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bla
35 changes: 35 additions & 0 deletions test/post_fetch_helpers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Test
using DataDeps: unpack, p7zip

# Runs `f()` and returns what would normally be printed to stdout
function capture_stdout(f)
std = stdout
r, w = redirect_stdout()
try
f()
finally
redirect_stdout(std)
close(w)
end
output = read(r, String)
return output
Comment on lines +6 to +15
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we do: const capture_stdout = sprint ∘ redirect_stdout ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, let me look into that (copy pasting this results in an error, but may be workable)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think there must be a much shorter way to do this.
Did you get a chance to look at it?

end

@testset "unpack" begin

@testset "happy case" begin
# Create dummy zip
p7zip() do exe7z
run(`$exe7z a assets/test.zip assets/file1.txt -bso0 -bsp0`)
end

output = capture_stdout() do
unpack("assets/test.zip")
end
@test output == "" # silent
end

@testset "sad case" begin
@test_throws Exception unpack("assets/non-existent.zip")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is spelt wrong but:

Suggested change
@test_throws Exception unpack("assets/non-existent.zip")
# depending on Julia version maybe ErrorException or ProcessExittedExcept
@test_throws Union{ErrorException,ProcessExittedException} unpack("assets/non-existent.zip")

end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Test
"main",
"preupload",
"fetch_helpers",
"post_fetch_helpers",
]
@testset "tests" begin
for filename in tests
Expand Down