Sha256: 8c7b12c481eb514104b7331c844a41c73ec5f836f47a94b5024eea9cf95067cc

Contents?: true

Size: 1018 Bytes

Versions: 6

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require 'fileutils'
require 'bolt/error'

module Bolt
  class ProjectMigrator
    class Base
      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

6 entries across 6 versions & 1 rubygems

Version Path
bolt-2.35.0 lib/bolt/project_migrator/base.rb
bolt-2.34.0 lib/bolt/project_migrator/base.rb
bolt-2.33.2 lib/bolt/project_migrator/base.rb
bolt-2.33.1 lib/bolt/project_migrator/base.rb
bolt-2.32.0 lib/bolt/project_migrator/base.rb
bolt-2.31.0 lib/bolt/project_migrator/base.rb