Skip to content

Instantly share code, notes, and snippets.

@whoahbot
Forked from miah/halp.md
Last active January 3, 2016 02:18
Show Gist options
  • Save whoahbot/8394311 to your computer and use it in GitHub Desktop.
Save whoahbot/8394311 to your computer and use it in GitHub Desktop.

This is a sample from a tar file class I created for a chef cookbook. In this example I'm iterating over entries in the tar file. Because of the way tar handles filenames over 100 chars (././@LongLink) I have to do something to register that i'm dealing a longlink and treat the next entry differently.

I would love any advice on how to clean this up. Its a super long method, I especially don't like that I have to set full_name to nil and twice.

Code here

Tar Longlink

def extract_tar
if valid_archive_and_destination?(@archive, @destination)
destinations = tar_reader(gzip_reader(@archive)).map do |entry|
if longlink?(entry)
[get_destination(@destination, longlink(entry)), entry]
else
[get_destination(@destination, link(entry)), entry]
end
end
destinations.each do |dest, entry|
Chef::Log.debug("Destination is #{ dest }")
write_file(dest, entry)
end
else
Chef::Log.info("Archive #{ @archive } is invalid.")
end
end
@whoahbot
Copy link
Author

You can probably extract the building of the entry, destination tuples into it's own function as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment