Class: Archive::Zip::Entry::Directory

Inherits:
Object
  • Object
show all
Includes:
Archive::Zip::Entry
Defined in:
lib/archive/zip/entry.rb

Overview

Archive::Zip::Entry::Directory represents a directory entry within a Zip archive.

Constant Summary

Constants included from Archive::Zip::Entry

FLAG_DATA_DESCRIPTOR_FOLLOWS, FLAG_ENCRYPTED

Instance Attribute Summary

Attributes included from Archive::Zip::Entry

#atime, #comment, #compression_codec, #encryption_codec, #expected_data_descriptor, #gid, #mode, #mtime, #password, #raw_data, #uid, #zip_path

Instance Method Summary collapse

Methods included from Archive::Zip::Entry

#add_extra_field, #dump_central_file_record, #dump_local_file_record, expand_path, #file?, from_file, #initialize, parse, #symlink?

Instance Method Details

#directory?Boolean

Returns true.

Returns:

  • (Boolean)

825
826
827
# File 'lib/archive/zip/entry.rb', line 825

def directory?
  true
end

#extract(options = {}) ⇒ Object

Extracts this entry.

options is a Hash optionally containing the following:

:file_path

Specifies the path to which this entry will be extracted. Defaults to the zip path of this entry.

:permissions

When set to false (the default), POSIX mode/permission bits will be ignored. Otherwise, they will be restored if possible.

:ownerships

When set to false (the default), user and group ownerships will be ignored. On most systems, only a superuser is able to change ownerships, so setting this option to true as a regular user may have no effect.

:times

When set to false (the default), last accessed and last modified times will be ignored. Otherwise, they will be restored if possible.


852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/archive/zip/entry.rb', line 852

def extract(options = {})
  # Ensure that unspecified options have default values.
  file_path           = options.has_key?(:file_path) ?
                        options[:file_path].to_s :
                        @zip_path
  restore_permissions = options.has_key?(:permissions) ?
                        options[:permissions] :
                        false
  restore_ownerships  = options.has_key?(:ownerships) ?
                        options[:ownerships] :
                        false
  restore_times       = options.has_key?(:times) ?
                        options[:times] :
                        false

  # Make the directory.
  FileUtils.mkdir_p(file_path)

  # Restore the metadata.
  ::File.chmod(mode, file_path) if restore_permissions
  ::File.chown(uid, gid, file_path) if restore_ownerships
  ::File.utime(atime, mtime, file_path) if restore_times

  nil
end

#ftypeObject

Returns the file type of this entry as the symbol :directory.


820
821
822
# File 'lib/archive/zip/entry.rb', line 820

def ftype
  :directory
end

#mode=(mode) ⇒ Object

Overridden in order to ensure that the proper mode bits are set for a directory.


831
832
833
# File 'lib/archive/zip/entry.rb', line 831

def mode=(mode)
  super(040000 | (mode & 07777))
end

#zip_path=(zip_path) ⇒ Object

Inherits the behavior of Archive::Zip::Entry#zip_path= but ensures that there is a trailing slash (/) on the end of the path.


814
815
816
817
# File 'lib/archive/zip/entry.rb', line 814

def zip_path=(zip_path)
  super(zip_path)
  @zip_path += '/'
end