Merge pull request #402 from Unrud/locking
Implement locking of whole storage
This commit is contained in:
@@ -30,6 +30,7 @@ import os
|
||||
import pprint
|
||||
import base64
|
||||
import socket
|
||||
import socketserver
|
||||
import ssl
|
||||
import wsgiref.simple_server
|
||||
import re
|
||||
@@ -93,6 +94,14 @@ class HTTPSServer(HTTPServer):
|
||||
self.server_activate()
|
||||
|
||||
|
||||
class ThreadedHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
|
||||
pass
|
||||
|
||||
|
||||
class ThreadedHTTPSServer(socketserver.ThreadingMixIn, HTTPSServer):
|
||||
pass
|
||||
|
||||
|
||||
class RequestHandler(wsgiref.simple_server.WSGIRequestHandler):
|
||||
"""HTTP requests handler."""
|
||||
def log_message(self, *args, **kwargs):
|
||||
@@ -274,14 +283,6 @@ class Application:
|
||||
is_authenticated = self.is_authenticated(user, password)
|
||||
is_valid_user = is_authenticated or not user
|
||||
|
||||
if is_valid_user:
|
||||
items = self.Collection.discover(
|
||||
path, environ.get("HTTP_DEPTH", "0"))
|
||||
read_allowed_items, write_allowed_items = (
|
||||
self.collect_allowed_items(items, user))
|
||||
else:
|
||||
read_allowed_items, write_allowed_items = None, None
|
||||
|
||||
# Get content
|
||||
content_length = int(environ.get("CONTENT_LENGTH") or 0)
|
||||
if content_length:
|
||||
@@ -291,13 +292,26 @@ class Application:
|
||||
else:
|
||||
content = None
|
||||
|
||||
if is_valid_user and (
|
||||
(read_allowed_items or write_allowed_items) or
|
||||
(is_authenticated and function == self.do_PROPFIND) or
|
||||
function == self.do_OPTIONS):
|
||||
status, headers, answer = function(
|
||||
environ, read_allowed_items, write_allowed_items, content,
|
||||
user)
|
||||
if is_valid_user:
|
||||
if function in (self.do_GET, self.do_HEAD,
|
||||
self.do_OPTIONS, self.do_PROPFIND,
|
||||
self.do_REPORT):
|
||||
lock_mode = "r"
|
||||
else:
|
||||
lock_mode = "w"
|
||||
with self.Collection.acquire_lock(lock_mode):
|
||||
items = self.Collection.discover(
|
||||
path, environ.get("HTTP_DEPTH", "0"))
|
||||
read_allowed_items, write_allowed_items = (
|
||||
self.collect_allowed_items(items, user))
|
||||
if (read_allowed_items or write_allowed_items or
|
||||
is_authenticated and function == self.do_PROPFIND or
|
||||
function == self.do_OPTIONS):
|
||||
status, headers, answer = function(
|
||||
environ, read_allowed_items, write_allowed_items,
|
||||
content, user)
|
||||
else:
|
||||
status, headers, answer = NOT_ALLOWED
|
||||
else:
|
||||
status, headers, answer = NOT_ALLOWED
|
||||
|
||||
|
Reference in New Issue
Block a user