mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Add locks around password fetching
This commit is contained in:
parent
f43ef436b7
commit
d5254081f8
2 changed files with 17 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ import click
|
||||||
|
|
||||||
from . import AppContext
|
from . import AppContext
|
||||||
from .. import exceptions, log
|
from .. import exceptions, log
|
||||||
from ..utils import expand_path
|
from ..utils import expand_path, synchronized
|
||||||
|
|
||||||
SUFFIX = '.fetch'
|
SUFFIX = '.fetch'
|
||||||
|
|
||||||
|
|
@ -31,6 +31,7 @@ def expand_fetch_params(config):
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@synchronized()
|
||||||
def _fetch_value(opts, key):
|
def _fetch_value(opts, key):
|
||||||
if not isinstance(opts, list):
|
if not isinstance(opts, list):
|
||||||
raise ValueError('Invalid value for {}: Expected a list, found {!r}.'
|
raise ValueError('Invalid value for {}: Expected a list, found {!r}.'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
@ -178,3 +179,17 @@ def generate_href(ident=None, safe=SAFE_UID_CHARS):
|
||||||
return to_unicode(uuid.uuid4().hex)
|
return to_unicode(uuid.uuid4().hex)
|
||||||
else:
|
else:
|
||||||
return ident
|
return ident
|
||||||
|
|
||||||
|
|
||||||
|
def synchronized(lock=None):
|
||||||
|
if lock is None:
|
||||||
|
from threading import Lock
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
|
def inner(f):
|
||||||
|
@functools.wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
with lock:
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
return inner
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue