Class: Amp::Repositories::Stores::FilenameCacheStore
- Inherits:
-
BasicStore
- Object
- BasicStore
- Amp::Repositories::Stores::FilenameCacheStore
- Defined in:
- lib/amp/repository/store.rb
Overview
FilenameCacheStore
This version of the store uses a “Filename Cache”, which is just a file that names all the tracked files in the store. It also uses an even more advanced “hybrid” encoding for filenames that again ensure consistency across platforms. However, this encoding is non-reversible - but since we’re just doing file lookups anyway, that’s just ducky.
Constant Summary
Constants inherited from BasicStore
Instance Attribute Summary
Attributes inherited from BasicStore
#create_mode, #opener, #path, #path_joiner
Instance Method Summary collapse
-
#copy_list ⇒ Object
A more advanced list of files we need, properly joined and whatnot.
-
#datafiles ⇒ Object
Here’s how we walk through the files now.
-
#initialize(path, openerklass, pathjoiner) ⇒ FilenameCacheStore
constructor
Initializes the store.
-
#join(f) ⇒ Object
Properly joins the path, but hybrid-encodes the file’s path first.
Methods inherited from BasicStore
#calculate_mode, #do_walk, #walk
Constructor Details
#initialize(path, openerklass, pathjoiner) ⇒ FilenameCacheStore
Initializes the store. Sets up the cache right away.
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/amp/repository/store.rb', line 280 def initialize(path, openerklass, pathjoiner) @path_joiner = pathjoiner @path = pathjoiner.call(path, 'store') @create_mode = calculate_mode @path @_op = openerklass.new(@path) @_op.create_mode = @create_mode @_op.default = :open_file @opener = FilenameCache::FilenameCacheOpener.new(@_op) end |
Instance Method Details
#copy_list ⇒ Object
A more advanced list of files we need, properly joined and whatnot.
332 333 334 335 336 337 338 |
# File 'lib/amp/repository/store.rb', line 332 def copy_list d = BASIC_DATA_FILES + ['dh', 'fncache'] d.inject ['requires', '00changelog.i'] do |a, f| a + @path_joiner.call('store', f) end result end |
#datafiles ⇒ Object
Here’s how we walk through the files now. Oh, look, we don’t need to do annoying directory traversal anymore! But we do have to maintain a consistent fnstore file. I think I can live with that.
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/amp/repository/store.rb', line 302 def datafiles rewrite = false existing = [] pjoin = @path_joiner spath = @path result = [] FilenameCache.parse(@_op) do |f| ef = Stores.hybrid_encode f begin st = File.stat(@path_joiner.call(spath, ef)) yield [f, ef, st.size] if block_given? result << [f, ef, st.size] unless block_given? existing << f rescue Errno::ENOENT rewrite = true end end if rewrite fp = @_op.open('fncache', 'wb') existing.each do |p| fp.write(p + "\n") end fp.close end result end |
#join(f) ⇒ Object
Properly joins the path, but hybrid-encodes the file’s path first.
294 295 296 |
# File 'lib/amp/repository/store.rb', line 294 def join(f) @path_joiner.call(@path, Stores.hybrid_encode(f)) end |