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 +1 -1
- data/lib/apache/upload_merger/version.rb +1 -1
- data/lib/apache/upload_merger.rb +27 -10
- metadata +3 -3
data/README
CHANGED
data/lib/apache/upload_merger.rb
CHANGED
@@ -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.
|
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]
|
63
|
-
src =
|
64
|
+
path = url[map[0], 1].untaint and
|
65
|
+
src = find(map[1], path)
|
64
66
|
|
65
|
-
|
66
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
17
|
+
date: 2010-02-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|