Module: WebHDFS::FileUtils

Defined in:
lib/rake_hdfs/hdfs_fileutils.rb

Class Method Summary collapse

Class Method Details

.exist?(file, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/rake_hdfs/hdfs_fileutils.rb', line 4

def exist?(file, options={})
  begin
    client.stat(file, options)
    return true
  rescue FileNotFoundError => e
    return false
  end
end

.ls(path, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/rake_hdfs/hdfs_fileutils.rb', line 13

def ls(path, options={})
  opts = options.dup
  fu_log "ls #{path}" if opts.delete(:verbose)
  client.list(path, options)
end

.mtime(path, options = {}) ⇒ Object



39
40
41
42
# File 'lib/rake_hdfs/hdfs_fileutils.rb', line 39

def mtime(path, options = {})
  file_stat = stat(path, options)
  file_stat["modificationTime"]
end

.stat(path, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/rake_hdfs/hdfs_fileutils.rb', line 20

def stat(path, options={})
  opts = options.dup
  fu_log "stat #{path}" if opts.delete(:verbose)
  client.stat(path, options)
end

.uptodate?(new, old_list, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'lib/rake_hdfs/hdfs_fileutils.rb', line 27

def uptodate?(new, old_list, options = {})
  return false unless exist?(new)
  new_time = mtime(new)
  old_list.each do |old|
    if exist?(old)
      return false unless new_time > mtime(old)
    end
  end
  true
end