Sha256: 7dc20b0f9d9d29b82d4d9a20967abc6e09a4b2342744220ecf93a29dd9e12ff6

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'fileutils'
require_relative '../../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

17 entries across 17 versions & 1 rubygems

Version Path
bolt-3.29.0 lib/bolt/project_manager/migrator.rb
bolt-3.28.0 lib/bolt/project_manager/migrator.rb
bolt-3.27.4 lib/bolt/project_manager/migrator.rb
bolt-3.27.2 lib/bolt/project_manager/migrator.rb
bolt-3.27.1 lib/bolt/project_manager/migrator.rb
bolt-3.26.2 lib/bolt/project_manager/migrator.rb
bolt-3.26.1 lib/bolt/project_manager/migrator.rb
bolt-3.25.0 lib/bolt/project_manager/migrator.rb
bolt-3.24.0 lib/bolt/project_manager/migrator.rb
bolt-3.23.1 lib/bolt/project_manager/migrator.rb
bolt-3.23.0 lib/bolt/project_manager/migrator.rb
bolt-3.22.1 lib/bolt/project_manager/migrator.rb
bolt-3.22.0 lib/bolt/project_manager/migrator.rb
bolt-3.21.0 lib/bolt/project_manager/migrator.rb
bolt-3.20.0 lib/bolt/project_manager/migrator.rb
bolt-3.19.0 lib/bolt/project_manager/migrator.rb
bolt-3.18.0 lib/bolt/project_manager/migrator.rb