class Archive::Tar::Minitar::Command::CommandList
Public Instance Methods
altname()
click to toggle source
# File lib/archive/tar/minitar/command.rb 622 def altname 623 "ls" 624 end
call(args, opts = {}, ioe = {})
click to toggle source
# File lib/archive/tar/minitar/command.rb 634 def call(args, opts = {}, ioe = {}) 635 argv = [] 636 output = nil 637 dest = "." 638 files = [] 639 opts[:field] = "name" 640 641 while (arg = args.shift) 642 case arg 643 when '--sort', '-S' 644 opts[:sort] = true 645 opts[:field] = args.shift 646 when '--reverse', '-R' 647 opts[:reverse] = true 648 opts[:sort] = true 649 when '--uncompress', '-z' 650 opts[:uncompress] = true 651 when '-l' 652 opts[:verbose] = true 653 else 654 argv << arg 655 end 656 end 657 658 if argv.size < 1 659 ioe[:output] << "Not enough arguments.\n\n" 660 CommandPattern["help"][["list"]] 661 return 255 662 end 663 664 input = argv.shift 665 if '-' == input 666 opts[:name] = "STDIN" 667 input = ioe[:input] 668 else 669 opts[:name] = input 670 input = File.open(input, "rb") 671 end 672 673 if opts[:name] =~ /\.tar\.gz$|\.tgz$/ or opts[:uncompress] 674 input = Zlib::GzipReader.new(input) 675 end 676 677 files << argv.to_a 678 files.flatten! 679 680 if opts[:verbose] or opts[:progress] 681 format = "%10s %4d %8s %8s %8d %12s %s" 682 datefmt = "%b %d %Y" 683 timefmt = "%b %d %H:%M" 684 fields = %w(permissions inodes user group size date fullname) 685 else 686 format = "%s" 687 fields = %w(fullname) 688 end 689 690 opts[:field] = opts[:field].intern 691 opts[:field] = :full_name if opts[:field] == :name 692 693 output = [] 694 695 Archive::Tar::Minitar::Input.open(input) do |inp| 696 today = Time.now 697 oneyear = Time.mktime(today.year - 1, today.month, today.day) 698 inp.each do |entry| 699 value = format % fields.map do |ff| 700 case ff 701 when "permissions" 702 s = entry.directory? ? "d" : "-" 703 s << modestr(entry.mode / 0100) 704 s << modestr(entry.mode / 0010) 705 s << modestr(entry.mode) 706 when "inodes" 707 entry.size / 512 708 when "user" 709 entry.uname || entry.uid || 0 710 when "group" 711 entry.gname || entry.gid || 0 712 when "size" 713 entry.size 714 when "date" 715 if Time.at(entry.mtime) > (oneyear) 716 Time.at(entry.mtime).strftime(timefmt) 717 else 718 Time.at(entry.mtime).strftime(datefmt) 719 end 720 when "fullname" 721 entry.full_name 722 end 723 end 724 725 if opts[:sort] 726 output << [entry.send(opts[:field]), value] 727 else 728 ioe[:output] << value << "\n" 729 end 730 731 end 732 end 733 734 if opts[:sort] 735 output = output.sort { |a, b| a[0] <=> b[0] } 736 if opts[:reverse] 737 output.reverse_each { |oo| ioe[:output] << oo[1] << "\n" } 738 else 739 output.each { |oo| ioe[:output] << oo[1] << "\n" } 740 end 741 end 742 743 0 744 end
help()
click to toggle source
# File lib/archive/tar/minitar/command.rb 746 def help 747 help = <<-EOH 748 minitar list [OPTIONS] <tarfile|-> [<file>+] 749 750 Lists files in an existing tarfile. If the tarfile is named .tar.gz or 751 .tgz, then it will be uncompressed automatically. If the tarfile is "-", 752 then it will be read from standard input (stdin) so that minitar may be 753 piped. 754 755 If --verbose or --progress is specified, then the file list will be 756 similar to that produced by the Unix command "ls -l". 757 758 list Options: 759 --uncompress, -z Uncompresses the tarfile with gzip. 760 --sort [<FIELD>], -S Sorts the list of files by the specified 761 field. The sort defaults to the filename. 762 --reverse, -R Reverses the sort. 763 -l Lists the files in detail. 764 765 Sort Fields: 766 name, mtime, size 767 768 EOH 769 end
modestr(mode)
click to toggle source
# File lib/archive/tar/minitar/command.rb 626 def modestr(mode) 627 s = "---" 628 s[0] = ?r if (mode & 4) == 4 629 s[1] = ?w if (mode & 2) == 2 630 s[2] = ?x if (mode & 1) == 1 631 s 632 end
name()
click to toggle source
# File lib/archive/tar/minitar/command.rb 618 def name 619 "list" 620 end