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
. -
#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, #dump_central_file_record, #dump_local_file_record, expand_path, #file?, from_file, #initialize, parse, #symlink?
Instance Method Details
#directory? ⇒ Boolean
Returns true
.
833 834 835 |
# File 'lib/archive/zip/entry.rb', line 833 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 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.
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/archive/zip/entry.rb', line 860 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
.
828 829 830 |
# File 'lib/archive/zip/entry.rb', line 828 def ftype :directory end |
#mode=(mode) ⇒ Object
Overridden in order to ensure that the proper mode bits are set for a directory.
839 840 841 |
# File 'lib/archive/zip/entry.rb', line 839 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.
822 823 824 825 |
# File 'lib/archive/zip/entry.rb', line 822 def zip_path=(zip_path) super(zip_path) @zip_path += '/' end |