shuck 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shuck (0.0.3)
4
+ shuck (0.0.4)
5
5
  builder
6
6
  thor
7
7
 
@@ -1,9 +1,14 @@
1
1
  require 'fileutils'
2
2
  require 'time'
3
+ require 'shuck/s3_object'
3
4
  require 'shuck/bucket'
5
+ require 'digest/md5'
6
+ require 'yaml'
4
7
 
5
8
  module Shuck
6
9
  class FileStore
10
+ SHUCK_METADATA_DIR = ".shuck_metadataFFF"
11
+
7
12
  def initialize(root)
8
13
  @root = root
9
14
  @buckets = []
@@ -33,26 +38,53 @@ module Shuck
33
38
 
34
39
  def get_object(bucket,object)
35
40
  begin
36
- io = File.open(File.join(@root,bucket,object),'rb')
37
- return io
41
+ real_obj = S3Object.new
42
+ obj_root = File.join(@root,bucket,object,SHUCK_METADATA_DIR)
43
+ metadata = YAML.parse(File.open(File.join(obj_root,"metadata"),'rb').read)
44
+ real_obj.name = object
45
+ real_obj.md5 = metadata[:md5].value
46
+ real_obj.io = File.open(File.join(obj_root,"content"),'rb')
47
+ return real_obj
38
48
  rescue
39
49
  puts $!
40
50
  return nil
41
51
  end
42
52
  end
43
53
 
54
+ def object_metadata(bucket,object)
55
+ end
56
+
44
57
  def store_object(bucket,object,request)
45
58
  begin
46
59
  filename = File.join(@root,bucket,object)
47
- parent_dir = File.dirname(filename)
48
- FileUtils.mkdir_p(parent_dir)
49
- File.open(filename,'w') do |f|
60
+ FileUtils.mkdir_p(filename)
61
+
62
+ metadata_dir = File.join(filename,SHUCK_METADATA_DIR)
63
+ FileUtils.mkdir_p(metadata_dir)
64
+
65
+ content = File.join(filename,SHUCK_METADATA_DIR,"content")
66
+ metadata = File.join(filename,SHUCK_METADATA_DIR,"metadata")
67
+
68
+ md5 = Digest::MD5.new
69
+ File.open(content,'w') do |f|
50
70
  request.body do |chunk|
51
71
  f << chunk
72
+ md5 << chunk
52
73
  end
53
74
  end
75
+ metadata_struct = {}
76
+ metadata_struct[:md5] = md5.hexdigest
77
+
78
+ File.open(metadata,'w') do |f|
79
+ f << YAML::dump(metadata_struct)
80
+ end
81
+ obj = S3Object.new
82
+ obj.md5 = metadata_struct[:md5]
83
+ return obj
54
84
  rescue
55
85
  puts $!
86
+ $!.backtrace.each { |line| puts line }
87
+ return nil
56
88
  end
57
89
  end
58
90
  end
@@ -1,5 +1,5 @@
1
1
  module Shuck
2
2
  class S3Object
3
- attr_accessor :name,:size,:creation_date
3
+ attr_accessor :name,:size,:creation_date,:md5,:io
4
4
  end
5
5
  end
data/lib/shuck/server.rb CHANGED
@@ -47,12 +47,14 @@ module Shuck
47
47
  end
48
48
  else
49
49
  object = elems[1,elems.size].join('/')
50
- io = @store.get_object(bucket,object)
51
- if io
50
+ real_obj = @store.get_object(bucket,object)
51
+ if real_obj
52
52
  response.status = 200
53
53
  response['Content-Type'] = "application/octet-stream"
54
- response.body = io
55
- response.chunked = true
54
+ response['Content-Length'] = real_obj.io.size
55
+ response['Etag'] = real_obj.md5
56
+ response.body = real_obj.io
57
+ puts real_obj.io.size
56
58
  else
57
59
  response.status = 404
58
60
  response.body = ""
@@ -66,6 +68,7 @@ module Shuck
66
68
  path_len = path.size
67
69
  path_style_request = true
68
70
  host = request["Host"]
71
+ puts host
69
72
  bucket = nil
70
73
  path_style_request = true
71
74
  if host != @hostname
@@ -92,10 +95,12 @@ module Shuck
92
95
  @store.create_bucket(bucket)
93
96
  else
94
97
  object = elems[1,elems.size].join('/')
95
- @store.store_object(bucket,object,request)
98
+ real_obj = @store.store_object(bucket,object,request)
99
+ response['Etag'] = real_obj.md5
96
100
  end
97
101
  else
98
- @store.store_object(bucket,path,request)
102
+ real_obj = @store.store_object(bucket,path,request)
103
+ response['Etag'] = real_obj.md5
99
104
  end
100
105
  end
101
106
  response.status = 200
data/lib/shuck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shuck
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -6,7 +6,7 @@ require 'right_aws'
6
6
  class RightAWSCommandsTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
- @s3 = RightAws::S3Interface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => false, :logger => Logger.new('/tmp/x.log'), :server => 'localhost', :port => 10453, :protocol => 'http' })
9
+ @s3 = RightAws::S3Interface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => false, :server => 'localhost', :port => 10453, :protocol => 'http' })
10
10
  end
11
11
 
12
12
  def teardown
@@ -31,7 +31,7 @@ class RightAWSCommandsTest < Test::Unit::TestCase
31
31
  500000.times do
32
32
  buffer << "#{(rand * 100).to_i}"
33
33
  end
34
- #
34
+
35
35
  buf_len = buffer.length
36
36
  @s3.put("s3media","big",buffer)
37
37
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Curtis Spencer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-11 00:00:00 -08:00
17
+ date: 2010-12-12 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency