Sha256: eea1f80758c1e371c5416f4a832772dcdb94a012fdda93d64b48debc072045cd

Contents?: true

Size: 1021 Bytes

Versions: 31

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

require 'fileutils'
require 'bolt/error'

module Bolt
  class ProjectManager
    class Migrator
      def initialize(outputter)
        @outputter = outputter
      end

      protected def backup_file(origin_path, backup_dir)
        unless File.exist?(origin_path)
          @outputter.print_action_step(
            "Could not find file #{origin_path}, skipping backup."
          )
          return
        end

        date = Time.new.strftime("%Y%m%d_%H%M%S%L")
        FileUtils.mkdir_p(backup_dir)

        filename = File.basename(origin_path)
        backup_path = File.join(backup_dir, "#{filename}.#{date}.bak")

        @outputter.print_action_step(
          "Backing up #{filename} from #{origin_path} to #{backup_path}"
        )

        begin
          FileUtils.cp(origin_path, backup_path)
        rescue StandardError => e
          raise Bolt::FileError.new("#{e.message}; unable to create backup of #{filename}.", origin_path)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
bolt-3.17.0 lib/bolt/project_manager/migrator.rb
bolt-3.16.1 lib/bolt/project_manager/migrator.rb
bolt-3.16.0 lib/bolt/project_manager/migrator.rb
bolt-3.15.0 lib/bolt/project_manager/migrator.rb
bolt-3.14.1 lib/bolt/project_manager/migrator.rb
bolt-3.13.0 lib/bolt/project_manager/migrator.rb
bolt-3.12.0 lib/bolt/project_manager/migrator.rb
bolt-3.11.0 lib/bolt/project_manager/migrator.rb
bolt-3.10.0 lib/bolt/project_manager/migrator.rb
bolt-3.9.2 lib/bolt/project_manager/migrator.rb
bolt-3.9.1 lib/bolt/project_manager/migrator.rb
bolt-3.9.0 lib/bolt/project_manager/migrator.rb
bolt-3.8.1 lib/bolt/project_manager/migrator.rb
bolt-3.8.0 lib/bolt/project_manager/migrator.rb
bolt-3.7.1 lib/bolt/project_manager/migrator.rb
bolt-3.7.0 lib/bolt/project_manager/migrator.rb
bolt-3.6.1 lib/bolt/project_manager/migrator.rb
bolt-3.6.0 lib/bolt/project_manager/migrator.rb
bolt-3.5.0 lib/bolt/project_manager/migrator.rb
bolt-3.4.0 lib/bolt/project_manager/migrator.rb