rack-webdav 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ebc645c51bce135644ae41d8a5e81e07a33b2dc
4
- data.tar.gz: aedfa7f5b1128e2a48c518e9009f0e18cb01a945
3
+ metadata.gz: fe9bcf71471ed56fbeacc1c97d854223086c8a68
4
+ data.tar.gz: 17aa7559b9644e228f85713aae147797e54fd07b
5
5
  SHA512:
6
- metadata.gz: 87014d0f17fab49c5d1b6b738a192e3bf43a9727ff3174aaf9b1df0b0c898bc1c1a7b768f21173bf5b569bd0f781c175a905b9dbcb061e0d5a6b260f55fcd461
7
- data.tar.gz: 39d1a57fe8d17fae9494c68a09f45b192a929e67a49b0f5eb58510fedfe2cf831e33297ed3f2555dd55077f5872f492487ee34f4185eb4bccbbfda04b8aea867
6
+ metadata.gz: 1b6f548f567c363801d2a6fbd47aae372007e0df77acb2acfb32146b61b5fb77242d1a093826f3b0306b076b3120723b2e25da97e28072c39f995cdcda6caca1
7
+ data.tar.gz: d5d891c2aa56554f2ffc52e9522bc75e9cbd5f0aed227918e0739755b9f0fbd390a4746b95c7fcdc7d415aa294c66c22be523f50bcd7f64d57a8eb2f594a2edc
@@ -58,6 +58,12 @@ module RackWebDAV
58
58
 
59
59
  def put
60
60
  raise Forbidden if resource.collection?
61
+ locktoken = request_locktoken('LOCK_TOKEN')
62
+ locktoken ||= request_locktoken('IF')
63
+ locketag = request_locketag('IF')
64
+ raise PreconditionFailed if locketag && locketag != resource.etag
65
+ raise Locked if resource.locked?(locktoken, locketag)
66
+
61
67
  map_exceptions do
62
68
  resource.put
63
69
  end
@@ -73,6 +79,7 @@ module RackWebDAV
73
79
 
74
80
  def delete
75
81
  raise NotFound if not resource.exist?
82
+ raise Locked if resource.locked?(request_locktoken('LOCK_TOKEN'))
76
83
 
77
84
  delete_recursive(resource, errors = [])
78
85
 
@@ -98,6 +105,10 @@ module RackWebDAV
98
105
 
99
106
  def copy
100
107
  raise NotFound if not resource.exist?
108
+ # Source Lock Check
109
+ locktoken = request_locktoken('LOCK_TOKEN')
110
+ locktoken ||= request_locktoken('IF')
111
+ raise Locked if resource.locked?(locktoken) && !overwrite
101
112
 
102
113
  dest_uri = URI.parse(env['HTTP_DESTINATION'])
103
114
  destination = parse_destination(dest_uri)
@@ -107,6 +118,10 @@ module RackWebDAV
107
118
 
108
119
  dest = resource_class.new(destination, @request, @response, @options)
109
120
  raise PreconditionFailed if dest.exist? && !overwrite
121
+ # Destination Lock Check
122
+ locktoken = request_locktoken('LOCK_TOKEN')
123
+ locktoken ||= request_locktoken('IF')
124
+ raise Locked if dest.locked?(locktoken)
110
125
 
111
126
  dest = dest.child(resource.name) if dest.collection?
112
127
 
@@ -127,6 +142,7 @@ module RackWebDAV
127
142
 
128
143
  def move
129
144
  raise NotFound if not resource.exist?
145
+ raise Locked if resource.locked?(request_locktoken('LOCK_TOKEN'))
130
146
 
131
147
  dest_uri = URI.parse(env['HTTP_DESTINATION'])
132
148
  destination = parse_destination(dest_uri)
@@ -195,6 +211,9 @@ module RackWebDAV
195
211
 
196
212
  def proppatch
197
213
  raise NotFound if not resource.exist?
214
+ locktoken = request_locktoken('LOCK_TOKEN')
215
+ locktoken ||= request_locktoken('IF')
216
+ raise Locked if resource.locked?(locktoken)
198
217
 
199
218
  nodes = request_match("/d:propertyupdate[d:remove/d:prop/* or d:set/d:prop/*]//d:prop/*")
200
219
 
@@ -380,7 +399,14 @@ module RackWebDAV
380
399
  def request_locktoken(header)
381
400
  token = request.env["HTTP_#{header}"]
382
401
  return if token.nil? || token.empty?
383
- token.scan /^\(?<?(.+?)>?\)?$/
402
+ token.scan /<(opaquelocktoken:.+?)>/
403
+ return $1
404
+ end
405
+
406
+ def request_locketag(header)
407
+ etag = request.env["HTTP_#{header}"]
408
+ return if etag.nil? || etag.empty?
409
+ etag.scan /\[(.+?)\]/
384
410
  return $1
385
411
  end
386
412
 
@@ -485,9 +511,12 @@ module RackWebDAV
485
511
  locktype = request_match("/d:lockinfo/d:locktype/d:*").first
486
512
  locktype = locktype.name if locktype
487
513
  owner = request_match("/d:lockinfo/d:owner/d:href").first
514
+ owner ||= request_match("/d:lockinfo/d:owner").first
488
515
  owner = owner.text if owner
489
516
  locktoken = "opaquelocktoken:" + sprintf('%x-%x-%s', Time.now.to_i, Time.now.sec, resource.etag)
490
517
 
518
+ raise Locked if resource.other_owner_locked?(locktoken, owner)
519
+
491
520
  # Quick & Dirty - FIXME: Lock should become a new Class
492
521
  # and this dirty parameter passing refactored.
493
522
  unless resource.lock(locktoken, timeout, lockscope, locktype, owner)
@@ -185,13 +185,14 @@ module RackWebDAV
185
185
  @@locks = {}
186
186
 
187
187
  def lock(token, timeout, scope = nil, type = nil, owner = nil)
188
- if scope && type && owner
188
+ if scope && type
189
189
  # Create lock
190
190
  @@locks[token] = {
191
191
  :timeout => timeout,
192
192
  :scope => scope,
193
193
  :type => type,
194
- :owner => owner
194
+ :owner => owner,
195
+ :path => self.path
195
196
  }
196
197
  return true
197
198
  else
@@ -206,6 +207,38 @@ module RackWebDAV
206
207
  !!@@locks.delete(token)
207
208
  end
208
209
 
210
+ def locked?(token, etag = nil)
211
+ if token.nil?
212
+ # check parent directory match
213
+ already_locks = @@locks.select { |lock_token, lock|
214
+ found = false
215
+ Pathname.new(self.path).ascend { |v|
216
+ found = lock[:path].gsub(/\/$/, '') == v.to_s
217
+ break if found
218
+ }
219
+ lock if found
220
+ }
221
+ return !already_locks.empty?
222
+ else
223
+ lock_paths = @@locks.select { |lock_token, lock| lock[:path] == self.path }
224
+ self.exist? && @@locks.key?(token) == false && !lock_paths.empty?
225
+ end
226
+ end
227
+
228
+ def other_owner_locked?(token, owner)
229
+ return false if token.nil?
230
+ return false if @@locks.key?(token) && owner.nil?
231
+ other_owner = @@locks.select { |lock_token, lock|
232
+ lock[:path] == self.path
233
+ }.select { |lock_token, lock|
234
+ !lock[:owner].nil? && lock[:owner] != owner
235
+ }
236
+ !other_owner.empty?
237
+ end
238
+
239
+ def locks
240
+ @@locks
241
+ end
209
242
 
210
243
  private
211
244
 
@@ -4,7 +4,7 @@ module RackWebDAV
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 4
7
- PATCH = 4
7
+ PATCH = 5
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-webdav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koki Oyatsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri