Class: SafeZip::Entry
- Inherits:
-
Object
- Object
- SafeZip::Entry
- Defined in:
- lib/safe_zip/entry.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#zip_archive ⇒ Object
readonly
Returns the value of attribute zip_archive.
-
#zip_entry ⇒ Object
readonly
Returns the value of attribute zip_entry.
Instance Method Summary collapse
- #exist? ⇒ Boolean
- #extract ⇒ Object
-
#initialize(zip_archive, zip_entry, params) ⇒ Entry
constructor
A new instance of Entry.
- #path_dir ⇒ Object
- #real_path_dir ⇒ Object
Constructor Details
#initialize(zip_archive, zip_entry, params) ⇒ Entry
Returns a new instance of Entry.
8 9 10 11 12 13 |
# File 'lib/safe_zip/entry.rb', line 8 def initialize(zip_archive, zip_entry, params) @zip_archive = zip_archive @zip_entry = zip_entry @params = params @path = ::File.(zip_entry.name, params.extract_path) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/safe_zip/entry.rb', line 6 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/safe_zip/entry.rb', line 6 def path @path end |
#zip_archive ⇒ Object (readonly)
Returns the value of attribute zip_archive.
5 6 7 |
# File 'lib/safe_zip/entry.rb', line 5 def zip_archive @zip_archive end |
#zip_entry ⇒ Object (readonly)
Returns the value of attribute zip_entry.
5 6 7 |
# File 'lib/safe_zip/entry.rb', line 5 def zip_entry @zip_entry end |
Instance Method Details
#exist? ⇒ Boolean
23 24 25 |
# File 'lib/safe_zip/entry.rb', line 23 def exist? ::File.exist?(path) end |
#extract ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/safe_zip/entry.rb', line 27 def extract # do not extract if file is not part of target directory or target file return false unless matching_target_directory || matching_target_file # do not overwrite existing file raise SafeZip::Extract::AlreadyExistsError, "File already exists #{zip_entry.name}" if exist? create_path_dir if zip_entry.file? extract_file elsif zip_entry.directory? extract_dir elsif zip_entry.symlink? extract_symlink else raise SafeZip::Extract::UnsupportedEntryError, "File #{zip_entry.name} cannot be extracted" end rescue SafeZip::Extract::Error raise rescue Zip::EntrySizeError => e raise SafeZip::Extract::EntrySizeError, e. rescue StandardError => e raise SafeZip::Extract::ExtractError, e. end |
#path_dir ⇒ Object
15 16 17 |
# File 'lib/safe_zip/entry.rb', line 15 def path_dir ::File.dirname(path) end |
#real_path_dir ⇒ Object
19 20 21 |
# File 'lib/safe_zip/entry.rb', line 19 def real_path_dir ::File.realpath(path_dir) end |