Class: Nearline::Models::FileInformation
- Inherits:
-
Object
- Object
- Nearline::Models::FileInformation
- Defined in:
- lib/nearline/file_information.rb
Overview
Handles file paths and metadata for a file in a manifest Acts as a builder for archived_file by providing the construction parameters
Instance Attribute Summary collapse
-
#archived_file_parameters ⇒ Object
readonly
Returns the value of attribute archived_file_parameters.
-
#archived_path ⇒ Object
readonly
Returns the value of attribute archived_path.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#ftype ⇒ Object
readonly
Returns the value of attribute ftype.
-
#link_target ⇒ Object
readonly
Returns the value of attribute link_target.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#path_hash ⇒ Object
readonly
Returns the value of attribute path_hash.
-
#stat ⇒ Object
readonly
Returns the value of attribute stat.
Instance Method Summary collapse
- #build_parameters ⇒ Object
- #cleaned_file_path ⇒ Object
- #file_content_value ⇒ Object
- #ftype_lookup(file_path) ⇒ Object
- #generate_path_hash ⇒ Object
-
#initialize(file_path, manifest) ⇒ FileInformation
constructor
A new instance of FileInformation.
- #read_stat ⇒ Object
Constructor Details
#initialize(file_path, manifest) ⇒ FileInformation
Returns a new instance of FileInformation.
16 17 18 19 20 21 22 23 24 |
# File 'lib/nearline/file_information.rb', line 16 def initialize(file_path, manifest) @manifest = manifest @file_path = File.(file_path) @archived_path = cleaned_file_path @stat = read_stat @ftype = ftype_lookup(file_path) @path_hash = generate_path_hash @archived_file_parameters = build_parameters end |
Instance Attribute Details
#archived_file_parameters ⇒ Object (readonly)
Returns the value of attribute archived_file_parameters.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def archived_file_parameters @archived_file_parameters end |
#archived_path ⇒ Object (readonly)
Returns the value of attribute archived_path.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def archived_path @archived_path end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def file_path @file_path end |
#ftype ⇒ Object (readonly)
Returns the value of attribute ftype.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def ftype @ftype end |
#link_target ⇒ Object (readonly)
Returns the value of attribute link_target.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def link_target @link_target end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def manifest @manifest end |
#path_hash ⇒ Object (readonly)
Returns the value of attribute path_hash.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def path_hash @path_hash end |
#stat ⇒ Object (readonly)
Returns the value of attribute stat.
7 8 9 |
# File 'lib/nearline/file_information.rb', line 7 def stat @stat end |
Instance Method Details
#build_parameters ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nearline/file_information.rb', line 71 def build_parameters return nil if @stat.nil? { :system => @manifest.system, :path => @archived_path, :path_hash => @path_hash, :file_content => file_content_value, :uid => @stat.uid, :gid => @stat.gid, :mtime => @stat.mtime.to_i, :mode => @stat.mode, :ftype => @ftype } end |
#cleaned_file_path ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/nearline/file_information.rb', line 26 def cleaned_file_path # TODO: handle \\system\$x style Windows file references. if RUBY_PLATFORM =~/windows/ return @file_path[2..-1] end @file_path end |
#file_content_value ⇒ Object
55 56 57 58 |
# File 'lib/nearline/file_information.rb', line 55 def file_content_value return FileContent.new unless @ftype == "directory" return nil end |
#ftype_lookup(file_path) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nearline/file_information.rb', line 60 def ftype_lookup(file_path) if File.symlink?(file_path) @link_target = File.readlink file_path return "link" end if File.directory?(file_path) return "directory" end return "file" end |
#generate_path_hash ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nearline/file_information.rb', line 44 def generate_path_hash return nil if @stat.nil? target = [@manifest.system.name, @archived_path, @stat.uid, @stat.gid, @stat.mtime.to_i, @stat.mode].join(':') Digest::SHA1.hexdigest(target) end |
#read_stat ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/nearline/file_information.rb', line 34 def read_stat stat = nil begin stat = File.lstat(@file_path) rescue @manifest.add_log("File not found on lstat: #{@file_path}") end stat end |