Skip to content

Commit 422f194

Browse files
postmodernflavorjones
authored andcommitted
Support extracting .tar.xz files on OpenBSD.
* OpenBSD's `tar` does not support the `-J` flag, thus we must use `xzcat $file | tar xf - -C $dest` to first uncompress the `.tar.xz` file and pipe it into `tar` to then extract it.
1 parent 62d8f68 commit 422f194

1 file changed

Lines changed: 24 additions & 25 deletions

File tree

lib/mini_portile2/mini_portile.rb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -510,30 +510,6 @@ def log_file(action)
510510
}
511511
end
512512

513-
TAR_EXECUTABLES = %w[gtar bsdtar tar basic-bsdtar]
514-
def tar_exe
515-
@@tar_exe ||= begin
516-
TAR_EXECUTABLES.find { |c|
517-
which(c)
518-
} or raise("tar not found - please make sure that one of the following commands is in the PATH: #{TAR_EXECUTABLES.join(", ")}")
519-
end
520-
end
521-
522-
def tar_compression_switch(filename)
523-
case File.extname(filename)
524-
when '.gz', '.tgz'
525-
'z'
526-
when '.bz2', '.tbz2'
527-
'j'
528-
when '.xz'
529-
'J'
530-
when '.Z'
531-
'Z'
532-
else
533-
''
534-
end
535-
end
536-
537513
# From: http://stackoverflow.com/a/5471032/7672
538514
# Thanks, Mislav!
539515
#
@@ -570,12 +546,35 @@ def detect_host
570546
end
571547
end
572548

549+
TAR_EXECUTABLES = %w[gtar bsdtar tar basic-bsdtar]
550+
def tar_exe
551+
@@tar_exe ||= begin
552+
TAR_EXECUTABLES.find { |c|
553+
which(c)
554+
} or raise("tar not found - please make sure that one of the following commands is in the PATH: #{TAR_EXECUTABLES.join(", ")}")
555+
end
556+
end
557+
558+
def tar_command(file, target)
559+
case File.extname(file)
560+
when '.gz', '.tgz'
561+
[tar_exe, 'xzf', file, '-C', target]
562+
when '.bz2', '.tbz2'
563+
[tar_exe, 'xjf', file, '-C', target]
564+
when '.xz'
565+
# NOTE: OpenBSD's tar command does not support the -J option
566+
"xzcat #{file.shellescape} | #{tar_exe.shellescape} xf - -C #{target.shellescape}"
567+
else
568+
[tar_exe, 'xf', file, '-C', target]
569+
end
570+
end
571+
573572
def extract_file(file, target)
574573
filename = File.basename(file)
575574
FileUtils.mkdir_p target
576575

577576
message "Extracting #{filename} into #{target}... "
578-
execute('extract', [tar_exe, "#{tar_compression_switch(filename)}xf", file, "-C", target], {:cd => Dir.pwd, :initial_message => false})
577+
execute('extract', tar_command(file, target) , {:cd => Dir.pwd, :initial_message => false})
579578
end
580579

581580
# command could be an array of args, or one string containing a command passed to the shell. See

0 commit comments

Comments
 (0)