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 +1 -2
- data/lib/daps/server.rb +44 -18
- data/lib/daps/version.rb +1 -1
- data/lib/daps.rb +1 -1
- metadata +7 -7
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
|
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
|
-
|
21
|
+
ArchiveStreamer.call(env)
|
22
22
|
end
|
23
23
|
|
24
|
-
class
|
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
|
-
|
27
|
-
token =
|
28
|
-
if @env['daps.token'] != token
|
29
|
-
halt
|
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
|
-
|
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
|
-
|
49
|
-
|
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
data/lib/daps.rb
CHANGED
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:
|
4
|
+
hash: 119
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
10
|
- a
|
11
|
-
-
|
12
|
-
version: 0.0.1.a.
|
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:
|
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:
|
31
|
+
hash: 29
|
32
32
|
segments:
|
33
|
-
- 1
|
34
33
|
- 0
|
35
|
-
|
34
|
+
- 11
|
35
|
+
version: "0.11"
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
38
|
- !ruby/object:Gem::Dependency
|