From bed28bbb47637fd47107e73fa1225fbcceee8075 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 21 Aug 2014 08:13:56 -0700 Subject: Get adapters working with default facade for ChefFS --- lib/chef_zero/data_store/v1_to_v2_adapter.rb | 35 +++++++++++++++++++--------- lib/chef_zero/data_store/v2_to_v1_adapter.rb | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/chef_zero/data_store/v1_to_v2_adapter.rb b/lib/chef_zero/data_store/v1_to_v2_adapter.rb index e081fd1..cb7e122 100644 --- a/lib/chef_zero/data_store/v1_to_v2_adapter.rb +++ b/lib/chef_zero/data_store/v1_to_v2_adapter.rb @@ -19,8 +19,12 @@ module ChefZero def create_dir(path, name, *options) return nil if skip_organizations?(path, name) - fix_exceptions do - real_store.create_dir(path[2..-1], name, *options) + if path.size <= 1 + raise DataAlreadyExistsError.new(path + [ name ]) if !options[:recursive] + else + fix_exceptions do + real_store.create_dir(path[2..-1], name, *options) + end end end @@ -61,22 +65,34 @@ module ChefZero def list(path) return nil if skip_organizations?(path) - fix_exceptions do - real_store.list(path[2..-1]) + if path == [] + [ 'organizations' ] + elsif path == [ 'organizations' ] + [ single_org ] + else + fix_exceptions do + real_store.list(path[2..-1]) + end end end def exists?(path) - return nil if skip_organizations?(path) + return false if skip_organizations?(path) fix_exceptions do real_store.exists?(path[2..-1]) end end def exists_dir?(path) - return nil if skip_organizations?(path) - fix_exceptions do - real_store.exists_dir?(path[2..-1]) + return false if skip_organizations?(path) + if path == [] + [ 'organizations' ] + elsif path == [ 'organizations' ] + [ single_org ] + else + fix_exceptions do + real_store.exists_dir?(path[2..-1]) + end end end @@ -101,9 +117,6 @@ module ChefZero true else raise "Path #{path} must start with /organizations/#{single_org}" if path[0..1] != [ 'organizations', single_org ] - if !name - raise "Path #{path} must start with /organizations/#{single_org}/" if path.size <= 2 - end false end end diff --git a/lib/chef_zero/data_store/v2_to_v1_adapter.rb b/lib/chef_zero/data_store/v2_to_v1_adapter.rb index 6bc72c0..d663657 100644 --- a/lib/chef_zero/data_store/v2_to_v1_adapter.rb +++ b/lib/chef_zero/data_store/v2_to_v1_adapter.rb @@ -30,7 +30,7 @@ module ChefZero def clear real_store.clear - real_store.create_dir([ 'organizations' ], single_org) + real_store.create_dir([ 'organizations' ], single_org, :recursive) end def create_dir(path, name, *options) -- cgit v1.2.1