apache_upload_merger 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to apache_upload_merger version 0.0.1
5
+ This documentation refers to apache_upload_merger version 0.0.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -6,7 +6,7 @@ module Apache
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 1
9
+ TINY = 2
10
10
 
11
11
  class << self
12
12
 
@@ -34,6 +34,8 @@ module Apache
34
34
 
35
35
  class UploadMerger
36
36
 
37
+ MERGE_SIZE = 32 * 1024 * 1024
38
+
37
39
  MODE = Fcntl::O_CREAT|Fcntl::O_WRONLY|Fcntl::O_EXCL
38
40
 
39
41
  # Creates a new RubyHandler instance for the Apache web server. It
@@ -54,16 +56,16 @@ module Apache
54
56
  # determined by its URL prefix. Otherwise, the original error will
55
57
  # be thrown.
56
58
  def handler(request)
57
- request.setup_cgi_env
59
+ request.add_common_vars # REDIRECT_URL
58
60
 
59
61
  if url = request.subprocess_env['REDIRECT_URL'] and
60
62
  prefix = request.path_info and
61
63
  map = @map[prefix] and
62
- path = url[map[0], 1] and
63
- src = Dir[File.join(map[1], '*', path.untaint)].first
64
+ path = url[map[0], 1].untaint and
65
+ src = find(map[1], path)
64
66
 
65
- dest = File.join(request.server.document_root, prefix, path)
66
- copy(src.untaint, dest.untaint)
67
+ merge(src,
68
+ File.join(request.server.document_root, prefix, path).untaint)
67
69
 
68
70
  request.status = HTTP_OK
69
71
  request.internal_redirect(url)
@@ -76,12 +78,27 @@ module Apache
76
78
 
77
79
  private
78
80
 
79
- def copy(src, dest)
80
- File.open(src, 'r') { |r|
81
- File.open(dest, MODE, r.stat.mode) { |w|
82
- FileUtils.copy_stream(r, w)
83
- }
81
+ # TODO: make it fast *and* secure
82
+ def find(dir, path)
83
+ Dir["#{dir}/*/"].find { |subdir|
84
+ file = File.join(subdir, path).untaint
85
+ return file if File.exists?(file)
84
86
  }
87
+ end
88
+
89
+ # TODO: optimize the copying case
90
+ def merge(src, dest)
91
+ stat = File.stat(src)
92
+
93
+ if stat.size > MERGE_SIZE
94
+ File.symlink(src, dest)
95
+ else
96
+ File.open(src) { |src_|
97
+ File.open(dest, MODE, stat.mode) { |dest_|
98
+ FileUtils.copy_stream(src_, dest_)
99
+ }
100
+ }
101
+ end
85
102
  rescue Errno::EEXIST
86
103
  end
87
104
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jens Wille
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-22 00:00:00 +01:00
17
+ date: 2010-02-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20