Class: Nearline::Models::ArchivedFile::FileInformation

Inherits:
Object
  • Object
show all
Defined in:
lib/nearline/archived_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, manifest) ⇒ FileInformation

Returns a new instance of FileInformation.



45
46
47
48
49
50
51
52
# File 'lib/nearline/archived_file.rb', line 45

def initialize(file_path, manifest)
  @manifest = manifest
  @file_path = file_path
  @stat = read_stat
  @is_directory = File.directory?(file_path)
  @path_hash = generate_path_hash
  @archived_file_parameters = build_parameters
end

Instance Attribute Details

#archived_file_parametersObject (readonly)

Returns the value of attribute archived_file_parameters.



44
45
46
# File 'lib/nearline/archived_file.rb', line 44

def archived_file_parameters
  @archived_file_parameters
end

#is_directoryObject (readonly)

Returns the value of attribute is_directory.



44
45
46
# File 'lib/nearline/archived_file.rb', line 44

def is_directory
  @is_directory
end

#path_hashObject (readonly)

Returns the value of attribute path_hash.



44
45
46
# File 'lib/nearline/archived_file.rb', line 44

def path_hash
  @path_hash
end

#statObject (readonly)

Returns the value of attribute stat.



44
45
46
# File 'lib/nearline/archived_file.rb', line 44

def stat
  @stat
end

Instance Method Details

#build_parametersObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/nearline/archived_file.rb', line 80

def build_parameters
  return nil if @stat.nil?
  {
    :system_name => @manifest.system_name,
    :path => @file_path,
    :path_hash => @path_hash,
    :file_content => file_content_entry_for_files_only,
    :uid => @stat.uid,
    :gid => @stat.gid,
    :mtime => @stat.mtime.to_i,
    :mode => @stat.mode,
    :is_directory => @is_directory    
  }
end

#file_content_entry_for_files_onlyObject



75
76
77
78
# File 'lib/nearline/archived_file.rb', line 75

def file_content_entry_for_files_only
  return FileContent.fresh_entry unless @is_directory
  return nil
end

#generate_path_hashObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/nearline/archived_file.rb', line 64

def generate_path_hash
  return nil if @stat.nil?          
  target = [@manifest.system_name, 
    @file_path,
    @stat.uid,
    @stat.gid,
    @stat.mtime.to_i,
    @stat.mode].join(':')
  Digest::SHA1.hexdigest(target)
end

#read_statObject



54
55
56
57
58
59
60
61
62
# File 'lib/nearline/archived_file.rb', line 54

def read_stat
  stat = nil
  begin
    stat = File.stat(@file_path)
  rescue
    @manifest.add_log("File not found on stat: #{@file_path}")
  end
  stat
end