Sha256: 4c01aaa9ce231b348d3d412507c2be3c6568074ae17707b01433fb3683cb225c

Contents?: true

Size: 1.71 KB

Versions: 19

Compression:

Stored size: 1.71 KB

Contents

# Copyright (c) 2013-2014 SUSE LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com

class Migrate3To4 < Migration
  desc <<-EOT
    Schema version 4 adds a "type" attribute to changed_managed_files and config_files
    in order to support other file types like links.
  EOT

  def migrate
    ["changed_managed_files", "config_files"].each do |scope|
      if @hash.has_key?(scope)
        @hash[scope]["files"].each do |file|
          next if file["changes"] == ["deleted"]

          path = File.join(@path, scope, file["name"])
          file["type"] = if File.directory?(path) || path.end_with?("/")
            "dir"
          else
            "file"
          end
        end
      end
    end

    Dir.glob(File.join(@path, "/changed_managed_files/**/*")).reverse.each do |path|
      if File.directory?(path) && Dir.glob(File.join(path, "*")).empty?
        FileUtils.rm_r(path)
      end
    end

    Dir.glob(File.join(@path, "/config_files/**/*")).reverse.each do |path|
      if File.directory?(path) && Dir.glob(File.join(path, "*")).empty?
        FileUtils.rm_r(path)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
machinery-tool-1.18.0 schema/migrations/migrate3to4.rb
machinery-tool-1.17.0 schema/migrations/migrate3to4.rb
machinery-tool-1.16.4 schema/migrations/migrate3to4.rb
machinery-tool-1.16.3 schema/migrations/migrate3to4.rb
machinery-tool-1.16.2 schema/migrations/migrate3to4.rb
machinery-tool-1.16.1 schema/migrations/migrate3to4.rb
machinery-tool-1.16.0 schema/migrations/migrate3to4.rb
machinery-tool-1.15.0 schema/migrations/migrate3to4.rb
machinery-tool-1.14.2 schema/migrations/migrate3to4.rb
machinery-tool-1.14.1 schema/migrations/migrate3to4.rb
machinery-tool-1.14.0 schema/migrations/migrate3to4.rb
machinery-tool-1.13.0 schema/migrations/migrate3to4.rb
machinery-tool-1.12.0 schema/migrations/migrate3to4.rb
machinery-tool-1.11.2 schema/migrations/migrate3to4.rb
machinery-tool-1.11.1 schema/migrations/migrate3to4.rb
machinery-tool-1.11.0 schema/migrations/migrate3to4.rb
machinery-tool-1.10.0 schema/migrations/migrate3to4.rb
machinery-tool-1.9.1 schema/migrations/migrate3to4.rb
machinery-tool-1.9.0 schema/migrations/migrate3to4.rb