Class: OsCtl::Repo::Local::Repository
- Inherits:
-
Object
- Object
- OsCtl::Repo::Local::Repository
- Defined in:
- lib/osctl/repo/local/repository.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
protected
Returns the value of attribute index.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add(vendor, variant, arch, dist, ver, opts) ⇒ Object
- #create ⇒ Object
- #exist? ⇒ Boolean
- #find(vendor, variant, arch, distribution, version) ⇒ Base::Image?
- #images ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #install_symlink(type, base_path, link_name, target_name) ⇒ Object protected
-
#remove(image) ⇒ Object
Remove image from the repository.
- #set_default_variant(vendor, variant) ⇒ Object
- #set_default_vendor(vendor) ⇒ Object
Constructor Details
#initialize(path) ⇒ Repository
Returns a new instance of Repository.
7 8 9 10 |
# File 'lib/osctl/repo/local/repository.rb', line 7 def initialize(path) @path = File.join(path, "v#{SCHEMA}") @index = Local::Index.new(self) end |
Instance Attribute Details
#index ⇒ Object (readonly, protected)
Returns the value of attribute index.
117 118 119 |
# File 'lib/osctl/repo/local/repository.rb', line 117 def index @index end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/osctl/repo/local/repository.rb', line 5 def path @path end |
Instance Method Details
#add(vendor, variant, arch, dist, ver, opts) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/osctl/repo/local/repository.rb', line 21 def add(vendor, variant, arch, dist, ver, opts) t = Base::Image.new( self, vendor, variant, arch, dist, ver, tags: opts[:tags], image: opts[:image].keys.map(&:to_s) ) FileUtils.mkdir_p(t.abs_dir_path) opts[:image].each do |format, file| FileUtils.cp(file, t.abs_image_path(format)) end t..each do |tag| path = t.abs_tag_path(tag) if File.symlink?(path) next if File.readlink(path) == t.version File.unlink(path) elsif File.exist?(path) File.unlink(path) end File.symlink(t.version, path) end index.add(t) index.save end |
#create ⇒ Object
16 17 18 19 |
# File 'lib/osctl/repo/local/repository.rb', line 16 def create FileUtils.mkpath(path) index.save end |
#exist? ⇒ Boolean
12 13 14 |
# File 'lib/osctl/repo/local/repository.rb', line 12 def exist? index.exist? end |
#find(vendor, variant, arch, distribution, version) ⇒ Base::Image?
58 59 60 |
# File 'lib/osctl/repo/local/repository.rb', line 58 def find(vendor, variant, arch, distribution, version) index.find(vendor, variant, arch, distribution, version) end |
#images ⇒ Object
112 113 114 |
# File 'lib/osctl/repo/local/repository.rb', line 112 def images index.images end |
#install_symlink(type, base_path, link_name, target_name) ⇒ Object (protected)
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/osctl/repo/local/repository.rb', line 119 def install_symlink(type, base_path, link_name, target_name) path = File.join(base_path, link_name) target = File.join(base_path, target_name) if !Dir.exist?(target) raise GLI::BadCommandLine, "#{type} '#{target_name}' not found" elsif File.symlink?(path) return if File.readlink(path) == target_name File.unlink(path) elsif File.exist?(path) File.unlink(path) end File.symlink(target_name, path) end |
#remove(image) ⇒ Object
Remove image from the repository
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/osctl/repo/local/repository.rb', line 64 def remove(image) # Remove image from the index index.delete(image) index.save # Remove image image.image.each do |v| path = image.abs_image_path(v) File.unlink(path) if File.exist?(path) end # Remove tags image..each do |v| path = image.abs_tag_path(v) File.unlink(path) if File.symlink?(path) end # Remove empty dir from the version dir up to the repository root version_dir = image.abs_dir_path 5.times.map do |i| File.absolute_path(File.join(version_dir, *Array.new(i, '..'))) end.each do |dir| # Use Dir.empty?(dir) when we don't care for Ruby < 2.4 if (Dir.entries(dir) - %w{ . .. }).empty? Dir.rmdir(dir) else break end end end |
#set_default_variant(vendor, variant) ⇒ Object
106 107 108 109 110 |
# File 'lib/osctl/repo/local/repository.rb', line 106 def set_default_variant(vendor, variant) install_symlink('variant', File.join(path, vendor), 'default', variant) index.set_default_variant(vendor, variant) index.save end |
#set_default_vendor(vendor) ⇒ Object
100 101 102 103 104 |
# File 'lib/osctl/repo/local/repository.rb', line 100 def set_default_vendor(vendor) install_symlink('vendor', path, 'default', vendor) index.set_default_vendor(vendor) index.save end |