Sha256: d4326fadce7101c3ea24b44ec27d38fe9bc317ace1bfa48cbc276d611b13832b

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

require 'cgi'
require 'fileutils'
require 'find'

require 'fig/file_not_found_error'
require 'fig/logging'
require 'fig/protocol'

module Fig; end
module Fig::Protocol; end

# File transfers for the local filesystem.
class Fig::Protocol::File
  include Fig::Protocol

  def download_list(uri)
    packages = []
    unescaped_path = CGI.unescape uri.path
    return packages if ! ::File.exist?(unescaped_path)

    ls = ''
    Find.find(unescaped_path) {
      |file|

      if FileTest.directory? file
        ls << file.to_s
        ls << "\n"
      end
    }

    strip_paths_for_list(ls, packages, unescaped_path)

    return packages
  end

  # Determine whether we need to update something.  Returns nil to indicate
  # "don't know".
  def path_up_to_date?(uri, path, prompt_for_login)
    begin
      unescaped_path = CGI.unescape uri.path
      if ::File.size(unescaped_path) != ::File.size(path)
        return false
      end

      if ::File.mtime(unescaped_path) <= ::File.mtime(path)
        return true
      end

      return false
    rescue Errno::ENOENT => error
      raise Fig::FileNotFoundError.new error.message, uri
    end
  end

  # Returns whether the file was not downloaded because the file already
  # exists and is already up-to-date.
  def download(uri, path, prompt_for_login)
    begin
      unescaped_path = CGI.unescape uri.path
      FileUtils.cp(unescaped_path, path)

      return true
    rescue Errno::ENOENT => error
      raise Fig::FileNotFoundError.new error.message, uri
    end
  end

  def upload(local_file, uri)
    unescaped_path = CGI.unescape uri.path
    FileUtils.mkdir_p(::File.dirname(unescaped_path))
    FileUtils.cp(local_file, unescaped_path)

    return
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fig-1.23.0 lib/fig/protocol/file.rb
fig-1.22.1.beta.1 lib/fig/protocol/file.rb
fig-1.22.0 lib/fig/protocol/file.rb
fig-1.21.1.beta.2 lib/fig/protocol/file.rb
fig-1.21.1.beta.1 lib/fig/protocol/file.rb
fig-1.21.0 lib/fig/protocol/file.rb
fig-1.20.1.beta.1 lib/fig/protocol/file.rb
fig-1.20.0 lib/fig/protocol/file.rb
fig-1.19.0 lib/fig/protocol/file.rb
fig-1.18.0 lib/fig/protocol/file.rb
fig-1.17.0 lib/fig/protocol/file.rb
fig-1.16.1.beta.1 lib/fig/protocol/file.rb
fig-1.16.0 lib/fig/protocol/file.rb
fig-1.15.1.beta.2 lib/fig/protocol/file.rb
fig-1.15.1.beta.1 lib/fig/protocol/file.rb
fig-1.15.0 lib/fig/protocol/file.rb
fig-1.14.0 lib/fig/protocol/file.rb