8000 Load existing files at boot by DanielHeath · Pull Request #263 · jubos/fake-s3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Load existing files at boot #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/fakes3/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'fakes3/rate_limitable_file'
require 'digest/md5'
require 'yaml'

require 'shellwords'
module FakeS3
class FileStore
FAKE_S3_METADATA_DIR = ".fakes3_metadataFFF"
Expand All @@ -22,10 +22,24 @@ def initialize(root, quiet_mode)
@bucket_hash = {}
@quiet_mode = quiet_mode
Dir[File.join(root,"*")].each do |bucket|
next unless File.directory?(bucket)
bucket_name = File.basename(bucket)
bucket_obj = Bucket.new(bucket_name,Time.now,[])
@buckets << bucket_obj
@bucket_hash[bucket_name] = bucket_obj
Thread.new(bucket_obj, bucket) do |bucket_obj, bucket|
Dir.glob("#{bucket}/**/*").each do |path|
next if File.directory?(path)
stat = File.stat(path)
obj = S3Object.new
obj.name = path.sub(bucket + "/", '')
obj.modified_date = stat.mtime
obj.size = stat.size
obj.md5 = Digest::MD5.file(path).hexdigest
obj.content_type = `file --brief --mime #{Shellwords.escape(path)}`
bucket_obj.add(obj)
end
end
end
end

Expand All @@ -49,6 +63,7 @@ def rate_limit=(rate_limit)
end

def buckets
raise "no: #{@buckets.inspect}"
@buckets
end

Expand Down
0