483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
# File 'lib/chef/chef_fs/chef_fs_data_store.rb', line 483
def list(path)
if use_memory_store?(path)
@memory_store.list(path)
elsif path == [ "policies" ]
with_entry([ path[0] ]) do |policies|
policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq
rescue Chef::ChefFS::FileSystem::NotFoundError
[]
end
elsif path[0] == "policies" && path[2] == "revisions" && path.length == 3
with_entry([ path[0] ]) do |policies|
revisions = []
policies.children.each do |policy|
name, dash, revision = policy.name[0..-6].rpartition("-")
revisions << revision if name == path[1]
end
raise ChefZero::DataStore::DataNotFoundError.new(path) if revisions.empty?
revisions
end
elsif path[0] == "policy_groups" && path.length == 2
with_entry(path) do |entry|
[ "policies" ]
end
elsif path[0] == "policy_groups" && path[2] == "policies" && path.length == 3
with_entry(path[0..1]) do |entry|
policies = Chef::JSONCompat.parse(entry.read)["policies"] || {}
policies.keys
end
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 1
with_entry(path) do |entry|
if path[0] == "cookbook_artifacts"
entry.children.map { |child| child.name.rpartition("-")[0] }.uniq
elsif chef_fs.versioned_cookbooks
entry.children.map { |child| split_name_version(child.name)[0] }.uniq
else
entry.children.map(&:name)
end
rescue Chef::ChefFS::FileSystem::NotFoundError
[]
end
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 2
if chef_fs.versioned_cookbooks || path[0] == "cookbook_artifacts"
result = with_entry([ path[0] ]) do |entry|
entry.children.map { |child| split_name_version(child.name) }
.select { |name, version| name == path[1] }
.map { |name, version| version }
end
if result.empty?
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
result
else
version = get_single_cookbook_version(path)
[version]
end
else
result = with_entry(path) do |entry|
entry.children.map { |c| zero_filename(c) }.sort
rescue Chef::ChefFS::FileSystem::NotFoundError => e
if path_always_exists?(path)
[]
else
raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
end
end
if path == [] && ChefZero::VERSION.to_f < 4.4
result.reject! { |child| %w{policies policy_data cookbook_artifacts}.include?(child) }
end
result
end
end
|