Class: Archive::Zip::Entry::Symlink
- Inherits:
-
Object
- Object
- Archive::Zip::Entry::Symlink
- Includes:
- Archive::Zip::Entry
- Defined in:
- lib/archive/zip/entry.rb
Overview
Archive::Zip::Entry::Symlink represents a symlink entry withing 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
-
#dump_file_data(io) ⇒ Object
private
Write the link target to io as the file data for the entry.
-
#extract(options = {}) ⇒ Object
Extracts this entry.
-
#ftype ⇒ Object
Returns the file type of this entry as the symbol
:symlink
. -
#link_target ⇒ Object
Returns the link target for this entry.
-
#link_target=(link_target) ⇒ Object
Sets the link target for this entry.
-
#mode=(mode) ⇒ Object
Overridden in order to ensure that the proper mode bits are set for a symlink.
-
#symlink? ⇒ Boolean
Returns
true
.
Methods included from Archive::Zip::Entry
#add_extra_field, #central_extra_field_data, compare_file_records, #directory?, #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, #version_made_by
Instance Method Details
#dump_file_data(io) ⇒ Object (private)
Write the link target to io as the file data for the entry.
998 999 1000 |
# File 'lib/archive/zip/entry.rb', line 998 def dump_file_data(io) io.write(@link_target) 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. Not supported on all platforms. - :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. Not supported on all platforms.
Raises Archive::Zip::EntryError if the link_target attribute is not specified.
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'lib/archive/zip/entry.rb', line 957 def extract( = {}) raise Zip::EntryError, 'link_target is nil' if link_target.nil? # 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 # Create the containing directory tree if necessary. parent_dir = ::File.dirname(file_path) FileUtils.mkdir_p(parent_dir) unless ::File.exist?(parent_dir) # Create the symlink. ::File.symlink(link_target, file_path) # Restore the metadata. # NOTE: Ruby does not have the ability to restore atime and mtime on # symlinks at this time (version 1.8.6). begin ::File.lchmod(mode, file_path) if rescue NotImplementedError # Ignore on platforms that do not support lchmod. end begin ::File.lchown(uid, gid, file_path) if restore_ownerships rescue NotImplementedError # Ignore on platforms that do not support lchown. end nil end |
#ftype ⇒ Object
Returns the file type of this entry as the symbol :symlink
.
893 894 895 |
# File 'lib/archive/zip/entry.rb', line 893 def ftype :symlink end |
#link_target ⇒ Object
Returns the link target for this entry.
Raises Archive::Zip::EntryError if decoding the link target from an archive is required but fails.
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/archive/zip/entry.rb', line 912 def link_target return @link_target unless @link_target.nil? raw_data.rewind encryption_codec.decryptor(raw_data, password) do |decryptor| compression_codec.decompressor(decryptor) do |decompressor| @link_target = decompressor.read # Verify that the extracted data is good. begin unless expected_data_descriptor.nil? then expected_data_descriptor.verify(decompressor.data_descriptor) end rescue => e raise Zip::EntryError, "`#{zip_path}': #{e.message}" end end end @link_target end |
#link_target=(link_target) ⇒ Object
Sets the link target for this entry. As a side effect, the raw_data attribute is set to nil
.
934 935 936 937 |
# File 'lib/archive/zip/entry.rb', line 934 def link_target=(link_target) self.raw_data = nil @link_target = link_target end |
#mode=(mode) ⇒ Object
Overridden in order to ensure that the proper mode bits are set for a symlink.
904 905 906 |
# File 'lib/archive/zip/entry.rb', line 904 def mode=(mode) super(0120000 | (mode & 07777)) end |
#symlink? ⇒ Boolean
Returns true
.
898 899 900 |
# File 'lib/archive/zip/entry.rb', line 898 def symlink? true end |