Class: Recls::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/recls/entry.rb,
lib/recls/obsolete.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, file_stat, search_dir, flags) ⇒ Entry

initialises an entry instance from the given path, file_stat, and search_dir



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/recls/entry.rb', line 64

def initialize(path, file_stat, search_dir, flags)

  @file_stat    = file_stat

  @path         = Recls::Ximpl.absolute_path path
  @short_path   = nil
  @compare_path = Entry.get_compare_path_ @path
  @hash         = @compare_path.hash

  windows_drive, directory, basename, file_name, file_ext = Recls::Ximpl::Util.split_path @path

  @drive = windows_drive
  @directory_path = "#{windows_drive}#{directory}"
  @directory = directory ? directory : ''
  @directory_parts = Recls::Ximpl.directory_parts_from_directory directory
  @file_full_name = basename ? basename : ''
  @file_short_name = nil
  @file_name_only = file_name ? file_name : ''
  @file_extension = file_ext ? file_ext : ''

  @search_directory = search_dir
  @search_relative_path = Recls::Ximpl.derive_relative_path search_dir, @path
  @search_relative_directory_path = Recls::Ximpl.derive_relative_path search_dir, @directory_path
  @search_relative_directory = @search_relative_directory_path
  @search_relative_directory_parts = Recls::Ximpl.directory_parts_from_directory @search_relative_directory

  if 0 != (Recls::MARK_DIRECTORIES & flags) && directory?
    @path                 = Recls::Ximpl::Util.append_trailing_slash @path
    @search_relative_path = Recls::Ximpl::Util.append_trailing_slash @search_relative_path
  end

  @dev    = @file_stat.dev if @file_stat
  @ino    = @file_stat.ino if @file_stat
  @nlink  = @file_stat.nlink if @file_stat

  if Recls::Ximpl::OS::OS_IS_WINDOWS && @file_stat

    @dev              = @file_stat.by_handle_information.volume_id
    @ino              = @file_stat.by_handle_information.file_index
    @nlink            = @file_stat.by_handle_information.num_links
    @short_path       = @file_stat.short_path
    @file_short_name  = Recls::Ximpl::Util.split_path(@short_path)[2]
  else
  end
end

Instance Attribute Details

#compare_pathObject (readonly)

(String) A normalised form of #path that can be used in comparisons



114
115
116
# File 'lib/recls/entry.rb', line 114

def compare_path
  @compare_path
end

#directoryObject (readonly)

(String) The entry’s directory (excluding the #drive if on Windows)



125
126
127
# File 'lib/recls/entry.rb', line 125

def directory
  @directory
end

#directory_partsObject (readonly) Also known as: directoryParts

( [ String ] ) An array of directory parts, where each part ends in PATH_NAME_SEPARATOR



127
128
129
# File 'lib/recls/entry.rb', line 127

def directory_parts
  @directory_parts
end

#directory_pathObject (readonly) Also known as: dirname, directoryPath

(String) The full path of the entry’s directory (taking into account the #drive if on Windows)



122
123
124
# File 'lib/recls/entry.rb', line 122

def directory_path
  @directory_path
end

#driveObject (readonly) Also known as: uncDrive

(String) The (Windows) drive. nil if does not exist



120
121
122
# File 'lib/recls/entry.rb', line 120

def drive
  @drive
end

#file_extensionObject (readonly) Also known as: extension, fileExt

(String) The entry’s file extension



137
138
139
# File 'lib/recls/entry.rb', line 137

def file_extension
  @file_extension
end

#file_full_nameObject (readonly) Also known as: basename, file

(String) The entry’s file name (combination of #stem + #extension)



129
130
131
# File 'lib/recls/entry.rb', line 129

def file_full_name
  @file_full_name
end

#file_name_onlyObject (readonly) Also known as: stem, fileBaseName, fileName

(String) The entry’s file stem



134
135
136
# File 'lib/recls/entry.rb', line 134

def file_name_only
  @file_name_only
end

#file_short_nameObject (readonly) Also known as: shortFile

(String) The (Windows) short-form of #basename, or nil if not on Windows



131
132
133
# File 'lib/recls/entry.rb', line 131

def file_short_name
  @file_short_name
end

#pathObject (readonly)

(String) The full-path of the instance



116
117
118
# File 'lib/recls/entry.rb', line 116

def path
  @path
end

#search_directoryObject (readonly) Also known as: searchDirectory

(String) The search directory if specified; nil otherwise



140
141
142
# File 'lib/recls/entry.rb', line 140

def search_directory
  @search_directory
end

#search_relative_directoryObject (readonly)

(String) The #directory relative to #search_directory; nil if no search directory specified



144
145
146
# File 'lib/recls/entry.rb', line 144

def search_relative_directory
  @search_relative_directory
end

#search_relative_directory_partsObject (readonly)

( [ String ] ) The #directory_parts relative to #search_directory; nil if no search directory specified



148
149
150
# File 'lib/recls/entry.rb', line 148

def search_relative_directory_parts
  @search_relative_directory_parts
end

#search_relative_directory_pathObject (readonly)

(String) The #directory_path relative to #search_directory; nil if no search directory specified



146
147
148
# File 'lib/recls/entry.rb', line 146

def search_relative_directory_path
  @search_relative_directory_path
end

#search_relative_pathObject (readonly) Also known as: searchRelativePath

(String) The #path relative to #search_directory; nil if no search directory specified



142
143
144
# File 'lib/recls/entry.rb', line 142

def search_relative_path
  @search_relative_path
end

#short_pathObject (readonly)

(String) The (Windows) short-form of #path, or nil if not on Windows



118
119
120
# File 'lib/recls/entry.rb', line 118

def short_path
  @short_path
end

Instance Method Details

#<=>(rhs) ⇒ Object

compares this instance with rhs



362
363
364
365
# File 'lib/recls/entry.rb', line 362

def <=>(rhs)

  compare_path <=> rhs.compare_path
end

#==(rhs) ⇒ Object

determines whether rhs refers to the same path



346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/recls/entry.rb', line 346

def ==(rhs)

  case rhs
  when String

    return compare_path == Entry.get_compare_path_(rhs)
  when self.class

    return compare_path == rhs.compare_path
  else

    return false
  end
end

#archive?Boolean

(WINDOWS-ONLY) Indicates whether the entry has the archive bit

Returns:

  • (Boolean)


189
190
191
192
193
194
# File 'lib/recls/entry.rb', line 189

def archive?

  return false if @file_stat.nil?

  @file_stat.archive?
end

#compressed?Boolean

(WINDOWS-ONLY) Indicates whether the entry has the compressed bit

Returns:

  • (Boolean)


221
222
223
224
225
226
# File 'lib/recls/entry.rb', line 221

def compressed?

  return false if @file_stat.nil?

  @file_stat.compressed?
end

#devObject

indicates the device of the given entry

On Windows, this will be 0 if the entry cannot be opened



288
289
290
291
# File 'lib/recls/entry.rb', line 288

def dev

  @dev
end

#device?Boolean

(WINDOWS-ONLY) Indicates whether the entry is a device

Returns:

  • (Boolean)


197
198
199
200
201
202
# File 'lib/recls/entry.rb', line 197

def device?

  return false if @file_stat.nil?

  @file_stat.device?
end

#directory?Boolean Also known as: dir?, isDirectory

indicates whether the given entry represents a directory

Returns:

  • (Boolean)


238
239
240
241
242
243
# File 'lib/recls/entry.rb', line 238

def directory?

  return false if @file_stat.nil?

  @file_stat.directory?
end

#encrypted?Boolean

(WINDOWS-ONLY) Indicates whether the entry has the encrypted bit

Returns:

  • (Boolean)


229
230
231
232
233
234
# File 'lib/recls/entry.rb', line 229

def encrypted?

  return false if @file_stat.nil?

  @file_stat.encrypted?
end

#eql?(rhs) ⇒ Boolean

determines whether rhs is an instance of Recls::Entry and refers to the same path

Returns:

  • (Boolean)


333
334
335
336
337
338
339
340
341
342
343
# File 'lib/recls/entry.rb', line 333

def eql?(rhs)

  case rhs
  when self.class

    return compare_path == rhs.compare_path
  else

    return false
  end
end

#exist?Boolean

indicates whether the given entry existed at the time the entry instance was created

Returns:

  • (Boolean)


155
156
157
158
159
160
# File 'lib/recls/entry.rb', line 155

def exist?

  return false if @file_stat.nil?

  not @file_stat.nil?
end

#file?Boolean Also known as: isFile

indicates whether the given entry represents a file

Returns:

  • (Boolean)


248
249
250
251
252
253
# File 'lib/recls/entry.rb', line 248

def file?

  return false if @file_stat.nil?

  @file_stat.file?
end

#hashObject

the hash



368
369
370
371
# File 'lib/recls/entry.rb', line 368

def hash

  @hash
end

#hidden?Boolean

indicates whether the given entry is hidden

Returns:

  • (Boolean)


163
164
165
166
167
168
# File 'lib/recls/entry.rb', line 163

def hidden?

  return false if @file_stat.nil?

  @file_stat.hidden?
end

#inoObject

indicates the ino of the given entry

On Windows, this will be 0 if the entry cannot be opened



296
297
298
299
# File 'lib/recls/entry.rb', line 296

def ino

  @ino
end

#last_access_timeObject

indicates the last access time of the entry



313
314
315
316
317
318
# File 'lib/recls/entry.rb', line 313

def last_access_time

  return nil if @file_stat.nil?

  @file_stat.atime
end

#link?Boolean

indicates whether the given entry represents a link

Returns:

  • (Boolean)


256
257
258
259
260
261
# File 'lib/recls/entry.rb', line 256

def link?

  return false if @file_stat.nil?

  @file_stat.link?
end

#modification_timeObject Also known as: creationTime

indicates the modification time of the entry



321
322
323
324
325
326
# File 'lib/recls/entry.rb', line 321

def modification_time

  return nil if @file_stat.nil?

  @file_stat.mtime
end

number of links to the given entry

On Windows, this will be 0 if the entry cannot be opened



304
305
306
307
# File 'lib/recls/entry.rb', line 304

def nlink

  @nlink
end

#normal?Boolean

(WINDOWS-ONLY) Indicates whether the entry is normal

Returns:

  • (Boolean)


205
206
207
208
209
210
# File 'lib/recls/entry.rb', line 205

def normal?

  return false if @file_stat.nil?

  @file_stat.normal?
end

#readonly?Boolean Also known as: isReadOnly

indicates whether the given entry is readonly

Returns:

  • (Boolean)


171
172
173
174
175
176
# File 'lib/recls/entry.rb', line 171

def readonly?

  return false if @file_stat.nil?

  not @file_stat.writable?
end

#sizeObject

indicates the size of the given entry



275
276
277
278
279
280
# File 'lib/recls/entry.rb', line 275

def size

  return 0 if @file_stat.nil?

  @file_stat.size
end

#socket?Boolean

indicates whether the given entry represents a socket

Returns:

  • (Boolean)


264
265
266
267
268
269
# File 'lib/recls/entry.rb', line 264

def socket?

  return false if @file_stat.nil?

  @file_stat.socket?
end

#system?Boolean

(WINDOWS-ONLY) Indicates whether the entry has the system bit

Returns:

  • (Boolean)


181
182
183
184
185
186
# File 'lib/recls/entry.rb', line 181

def system?

  return false if @file_stat.nil?

  @file_stat.system?
end

#temporary?Boolean

(WINDOWS-ONLY) Indicates whether the entry has the temporary bit

Returns:

  • (Boolean)


213
214
215
216
217
218
# File 'lib/recls/entry.rb', line 213

def temporary?

  return false if @file_stat.nil?

  @file_stat.temporary?
end

#to_sObject

represents the entry as a string (in the form of the full path)



377
378
379
380
# File 'lib/recls/entry.rb', line 377

def to_s

  path
end

#to_strObject

represents the entry as a string (in the form of the full path)



383
384
385
386
# File 'lib/recls/entry.rb', line 383

def to_str

  path
end