Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Merge 6a69b73 into 10656ba
Browse files Browse the repository at this point in the history
  • Loading branch information
shin- committed Nov 21, 2014
2 parents 10656ba + 6a69b73 commit 4addb9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docker_registry/lib/index/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from ... import storage
from ... import toolkit
from .. import config
from . import Index
import sqlalchemy
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(self, database=None):
self._setup_database()
super(SQLAlchemyIndex, self).__init__()

@toolkit.exclusive_lock
def _setup_database(self):
session = self._session()
if self._engine.has_table(table_name=Version.__tablename__):
Expand Down
17 changes: 17 additions & 0 deletions docker_registry/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import distutils.version
import functools
import logging
import os
import random
import re
import string
Expand Down Expand Up @@ -278,6 +279,22 @@ def wrapper(repository, *args, **kwargs):
return wrapper


def exclusive_lock(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
lock_path = os.path.join(
'/var/lock', 'registry.{0}.lock'.format(f.func_name)
)
if os.path.exists(lock_path):
return
lock_file = open(lock_path, 'w')
lock_file.close()
result = f(*args, **kwargs)
os.remove(lock_path)
return result
return wrapper


def get_repository():
auth = flask.request.headers.get('authorization', '')
if not auth:
Expand Down

0 comments on commit 4addb9d

Please sign in to comment.