Class: Bosh::Cli::Versions::ReleasesDirMigrator
- Defined in:
- lib/cli/versions/releases_dir_migrator.rb
Instance Method Summary collapse
-
#initialize(releases_path, default_release_name, ui, release_type_name) ⇒ ReleasesDirMigrator
constructor
A new instance of ReleasesDirMigrator.
- #migrate ⇒ Object
- #needs_migration? ⇒ Boolean
Constructor Details
#initialize(releases_path, default_release_name, ui, release_type_name) ⇒ ReleasesDirMigrator
Returns a new instance of ReleasesDirMigrator.
5 6 7 8 9 10 |
# File 'lib/cli/versions/releases_dir_migrator.rb', line 5 def initialize(releases_path, default_release_name, ui, release_type_name) @releases_path = releases_path @default_release_name = default_release_name @ui = ui @release_type_name = release_type_name end |
Instance Method Details
#migrate ⇒ Object
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cli/versions/releases_dir_migrator.rb', line 28 def migrate return false unless needs_migration? unless Dir.exist?(@releases_path) raise "Releases path '#{@releases_path}' does not exist" end @ui.header("Migrating #{@release_type_name} releases".make_green) old_index = VersionsIndex.new(@releases_path) migrated_releases = Set.new release_versions_to_migrate.each do |data| release_name = data[:name] if migrated_releases.add?(release_name) @ui.say("Migrating release: #{release_name}") end release_path = File.join(@releases_path, release_name) FileUtils.mkdir_p(release_path) unless Dir.exist?(release_path) # move version record to new index file in release_path index_key = old_index.find_key_by_version(data[:version]) index_value = old_index[index_key] old_index.remove_version(index_key) new_index = VersionsIndex.new(release_path) new_index.add_version(index_key, index_value) # move tarball and manifest to release_path FileUtils.mv(data[:manifest_path], release_path) FileUtils.mv(data[:tarball_path], release_path) if File.exist?(data[:tarball_path]) end @ui.say("Migrating default release: #{@default_release_name}") create_release_symlink # initialize release name & format-version in index.yml old_index.save true end |
#needs_migration? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cli/versions/releases_dir_migrator.rb', line 12 def needs_migration? index_path = File.join(@releases_path, 'index.yml') return false unless File.exists?(index_path) index = VersionsIndex.load_index_yaml(index_path) format_version_string = index['format-version'] return true if format_version_string.nil? begin SemiSemantic::Version.parse(format_version_string) < VersionsIndex::CURRENT_INDEX_VERSION rescue ArgumentError, SemiSemantic::ParseError raise InvalidIndex, "Invalid versions index version in '#{index_path}', " + "'#{format_version_string}' given, SemiSemantic version expected" end end |