daps 0.0.1.a.4 → 0.0.1.a.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/daps/client.rb CHANGED
@@ -6,9 +6,8 @@ class Daps::Client
6
6
 
7
7
  def start!
8
8
  system(%{
9
- wget -T 300 -O /tmp/daps-#{@token}-client.tar.gz http://#{@remote}:#{@port}/#{@token} &&
9
+ wget -T 600 -O /tmp/daps-#{@token}-client.tar.gz http://#{@remote}:#{@port}/#{@token} &&
10
10
  tar --directory=#{@dir} -xzf /tmp/daps-#{@token}-client.tar.gz ;
11
- wget -q -O /dev/null http://#{@remote}:#{@port}/#{@token}/close ;
12
11
  rm -f /tmp/daps-#{@token}-client.tar.gz
13
12
  })
14
13
  end
data/lib/daps/server.rb CHANGED
@@ -18,35 +18,61 @@ class Daps::Server
18
18
  def call(env)
19
19
  env['daps.token'] = @token
20
20
  env['daps.dir'] = @dir
21
- Http.call(env)
21
+ ArchiveStreamer.call(env)
22
22
  end
23
23
 
24
- class Http < Sinatra::Base
24
+ class ArchiveStreamer < Cramp::Controller::Action
25
+ before_start :verify_token, :build_archive
26
+ on_start :prepare_stream
27
+ on_finish :terminate
25
28
 
26
- get '/:token/close' do
27
- token = params[:token]
28
- if @env['daps.token'] != token
29
- halt(403, {'Content-type' => 'text/plain'}, 'back off!')
29
+ def verify_token
30
+ @token = File.basename(@env['PATH_INFO'])
31
+ if @env['daps.token'] != @token
32
+ halt 403, {}, 'back off!!'
33
+ else
34
+ yield
30
35
  end
31
-
32
- File.unlink("/tmp/daps-#{token}-server.tar.gz")
33
- EM.stop_event_loop
34
36
  end
35
37
 
36
- get '/:token' do
37
- token = params[:token]
38
- if @env['daps.token'] != token
39
- halt(403, {'Content-type' => 'text/plain'}, 'back off!')
40
- end
41
-
38
+ def build_archive
42
39
  puts "Compressing files..."
43
40
  system(%{
44
41
  cd #{@env['daps.dir']} ;
45
- tar -czf /tmp/daps-#{token}-server.tar.gz . ;
42
+ tar -czf /tmp/daps-#{@token}-server.tar.gz . ;
46
43
  })
47
44
 
48
- puts "Transfering archive..."
49
- send_file "/tmp/daps-#{token}-server.tar.gz"
45
+ @length = File.size("/tmp/daps-#{@token}-server.tar.gz")
46
+ @archive = File.open("/tmp/daps-#{@token}-server.tar.gz")
47
+
48
+ yield
49
+ end
50
+
51
+ def respond_with
52
+ [200, {'Content-Type' => 'text/html', 'Content-Length' => @length.to_s}]
53
+ end
54
+
55
+ def prepare_stream
56
+ puts "Transferring archive..."
57
+ stream_chunks
58
+ end
59
+
60
+ def stream_chunks
61
+ if data = @archive.read(1024 * 8)
62
+ render data
63
+ EM.add_timer(0.01) { stream_chunks }
64
+ else
65
+ finish
66
+ end
67
+ end
68
+
69
+ def terminate
70
+ EM.next_tick {
71
+ if @env['daps.token'] == @token
72
+ File.unlink("/tmp/daps-#{@token}-server.tar.gz")
73
+ EM.stop_event_loop
74
+ end
75
+ }
50
76
  end
51
77
 
52
78
  end
data/lib/daps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Daps
2
- VERSION = '0.0.1.a.4'
2
+ VERSION = '0.0.1.a.5'
3
3
  end
data/lib/daps.rb CHANGED
@@ -3,7 +3,7 @@ module Daps
3
3
  require 'uri'
4
4
  require 'digest/sha1'
5
5
  require 'thor'
6
- require 'sinatra'
6
+ require 'cramp/controller'
7
7
 
8
8
  require 'daps/version'
9
9
  require 'daps/application'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 117
4
+ hash: 119
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 1
10
10
  - a
11
- - 4
12
- version: 0.0.1.a.4
11
+ - 5
12
+ version: 0.0.1.a.5
13
13
  platform: ruby
14
14
  authors:
15
15
  - Simon Menke
@@ -21,18 +21,18 @@ date: 2010-06-15 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- name: sinatra
24
+ name: cramp
25
25
  prerelease: false
26
26
  requirement: &id001 !ruby/object:Gem::Requirement
27
27
  none: false
28
28
  requirements:
29
29
  - - "="
30
30
  - !ruby/object:Gem::Version
31
- hash: 15
31
+ hash: 29
32
32
  segments:
33
- - 1
34
33
  - 0
35
- version: "1.0"
34
+ - 11
35
+ version: "0.11"
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency