Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Created November 2, 2016 11:34
Show Gist options
  • Save kenjiskywalker/f826c16554eed617a27daf0e7d7c54bb to your computer and use it in GitHub Desktop.
Save kenjiskywalker/f826c16554eed617a27daf0e7d7c54bb to your computer and use it in GitHub Desktop.

https://github.com/aws/aws-codedeploy-agent/blob/e28c7e14ed94cec4e29ceac6c75ed6ec8c6329ca/lib/instance_agent/plugins/codedeploy/install_instruction.rb#L223-L243

      class CopyCommand
        attr_reader :destination, :source
        def initialize(source, destination)
          @source = source
          @destination = destination
        end

        def execute(cleanup_file)
          raise "File already exists at #{@destination}"  if File.exists?(@destination)
          cleanup_file.puts(@destination)
          if File.symlink?(@source)
            FileUtils.symlink(File.readlink(@source), @destination)
          else
            FileUtils.copy(@source, @destination, :preserve => true)
          end
        end

        def to_h
          {:type => :copy, :source => @source, :destination => @destination}
        end
      end

https://github.com/aws/aws-codedeploy-agent/blob/e28c7e14ed94cec4e29ceac6c75ed6ec8c6329ca/lib/instance_agent/plugins/codedeploy/install_instruction.rb#L82-L89

        def copy(source, destination)
          destination = sanitize_dir_path(destination)
          log(:debug, "Copying #{source} to #{destination}")
          raise "Duplicate copy instruction to #{destination} from #{source} and #{@copy_targets[destination]}" if @copy_targets.has_key?(destination)
          raise "Duplicate copy instruction to #{destination} from #{source} which is already being installed as a directory" if @mkdir_targets.include?(destination)
          @command_array << CopyCommand.new(source, destination)
          @copy_targets[destination] = source
        end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment