Skip to content

Commit

Permalink
[2221] Fix where the pairtree marker is missing for some users
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Mar 12, 2012
1 parent 257bb13 commit bff6c3e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
30 changes: 28 additions & 2 deletions ckan/controllers/storage.py
Expand Up @@ -46,6 +46,18 @@ def fix_stupid_pylons_encoding(data):
data = m.groups()[0]
return data

def create_pairtree_marker(folder):
""" Creates the pairtree marker for tests if it doesn't exist """
directory = os.path.dirname(folder)
if not os.path.exists(directory):
os.makedirs(directory)

target = os.path.join(directory, 'pairtree_version0_1')
if os.path.exists(target):
return

open( target, 'wb').close()


def get_ofs():
"""Return a configured instance of the appropriate OFS driver.
Expand All @@ -56,6 +68,11 @@ def get_ofs():
if not k.startswith('ofs.') or k == 'ofs.impl':
continue
kw[k[4:]] = v

# Make sure we have created the marker file to avoid pairtree issues
if storage_backend == 'pairtree' and 'storage_dir' in kw:
create_pairtree_marker( kw['storage_dir'] )

ofs = get_impl(storage_backend)(**kw)
return ofs

Expand Down Expand Up @@ -83,9 +100,13 @@ def authorize(method, bucket, key, user, ofs):
class StorageController(BaseController):
'''Upload to storage backend.
'''
_ofs_impl = None

@property
def ofs(self):
return get_ofs()
if not StorageController._ofs_impl:
StorageController._ofs_impl = get_ofs()
return StorageController._ofs_impl


def upload(self):
Expand Down Expand Up @@ -165,9 +186,14 @@ def file(self, label):


class StorageAPIController(BaseController):

_ofs_impl = None

@property
def ofs(self):
return get_ofs()
if not StorageAPIController._ofs_impl:
StorageAPIController._ofs_impl = get_ofs()
return StorageAPIController._ofs_impl

@jsonpify
def index(self):
Expand Down
17 changes: 3 additions & 14 deletions ckan/tests/functional/test_storage.py
Expand Up @@ -5,18 +5,7 @@
import ckan.model as model
from ckan.tests import conf_dir, url_for, CreateTestData
from ckan.controllers.admin import get_sysadmins

def create_marker(folder):
""" Creates the pairtree marker for tests if it doesn't exist """
directory = os.path.dirname(folder)
if not os.path.exists(directory):
os.makedirs(directory)

target = os.path.join(folder, 'pairtree_version0_1')
if os.path.exists(target):
return

open( target, 'w').close()
from ckan.controllers.storage import create_pairtree_marker


class TestStorageAPIController:
Expand All @@ -29,7 +18,7 @@ def setup_class(cls):
config.local_conf['ofs.impl'] = 'pairtree'
config.local_conf['ckan.storage.bucket'] = 'ckantest'
config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
create_marker( config.local_conf['ofs.storage_dir'] )
create_pairtree_marker( config.local_conf['ofs.storage_dir'] )
wsgiapp = make_app(config.global_conf, **config.local_conf)
cls.app = paste.fixture.TestApp(wsgiapp)

Expand Down Expand Up @@ -58,7 +47,7 @@ def setup_class(cls):
config.local_conf['ckan.storage.bucket'] = 'ckantest'
config.local_conf['ofs.impl'] = 'pairtree'
config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
create_marker( config.local_conf['ofs.storage_dir'] )
create_pairtree_marker( config.local_conf['ofs.storage_dir'] )
wsgiapp = make_app(config.global_conf, **config.local_conf)
cls.app = paste.fixture.TestApp(wsgiapp)
CreateTestData.create()
Expand Down

0 comments on commit bff6c3e

Please sign in to comment.