Sha256: 4010365004c0ed6643a5c5d760a8cae196a833fd3d8c77b1c938bd1731a02169

Contents?: true

Size: 935 Bytes

Versions: 1

Compression:

Stored size: 935 Bytes

Contents

require 'fileutils'

module FileUtils
  class << self
    alias_method :old_mv, :mv

    # Override mv to ensure {safe_mv} is run if we are on the Windows platform.
    #
    # @see {FileUtils::mv}
    # @see {safe_mv}
    def mv(src, dest, options = {})
      if windows?
        safe_mv(src, dest, options)
      else
        old_mv(src, dest, options)
      end
    end

    # If we encounter Errno::EACCES, which seems to happen occasionally on Windows, 
    # try to copy and delete the file instead of moving it.
    #
    # @see https://github.com/RiotGames/berkshelf/issues/140
    # @see http://www.ruby-forum.com/topic/1044813
    #
    # @param [String] src
    # @param [String] dest
    # @param [Hash] options
    #   @see {FileUtils::mv}
    def safe_mv(src, dest, options = {})
      FileUtils.mv(src, dest, options)
    rescue Errno::EACCES
      FileUtils.cp_r(src, dest)
      FileUtils.rm_rf(src)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
berkshelf-0.6.0.beta3 lib/berkshelf/core_ext/file_utils.rb