Class: Archive::Zip::Entry::Directory
- Inherits:
-
Object
- Object
- Archive::Zip::Entry::Directory
- 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
-
#directory? ⇒ Boolean
Returns
true
. -
#dump_file_data(io) ⇒ Object
private
Directory entries do not have file data to write, so do nothing.
-
#extract(options = {}) ⇒ Object
Extracts this entry.
-
#ftype ⇒ Object
Returns the file type of this entry as the symbol
:directory
. -
#mode=(mode) ⇒ Object
Overridden in order to ensure that the proper mode bits are set for a directory.
-
#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.
Methods included from Archive::Zip::Entry
#add_extra_field, #central_extra_field_data, compare_file_records, #dummy, #dump_central_file_record, #dump_local_file_record, expand_path, #external_file_attributes, #file?, from_file, #initialize, #internal_file_attributes, #local_extra_field_data, parse, parse_central_extra_fields, parse_central_file_record, parse_local_extra_fields, parse_local_file_record, #symlink?, #version_made_by
Instance Method Details
#directory? ⇒ Boolean
Returns true
.
825 826 827 |
# File 'lib/archive/zip/entry.rb', line 825 def directory? true end |
#dump_file_data(io) ⇒ Object (private)
Directory entries do not have file data to write, so do nothing.
881 882 |
# File 'lib/archive/zip/entry.rb', line 881 def dump_file_data(io) 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 totrue
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( = {}) # Ensure that unspecified options have default values. file_path = .has_key?(:file_path) ? [:file_path].to_s : @zip_path = .has_key?(:permissions) ? [:permissions] : false restore_ownerships = .has_key?(:ownerships) ? [:ownerships] : false restore_times = .has_key?(:times) ? [:times] : false # Make the directory. FileUtils.mkdir_p(file_path) # Restore the metadata. ::File.chmod(mode, file_path) if ::File.chown(uid, gid, file_path) if restore_ownerships ::File.utime(atime, mtime, file_path) if restore_times nil end |
#ftype ⇒ Object
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 |