Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/qdumpfs/util.rb

Class Method Summary collapse

Class Method Details

.anything_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/qdumpfs/util.rb', line 29

def self.anything_exist?(path)
  FileTest.exist?(path) or FileTest.symlink?(path)
end


47
48
49
50
# File 'lib/qdumpfs/util.rb', line 47

def self.force_link(src, dest)
  File.unlink(dest) if File.anything_exist?(dest)
  File.link(src, dest)
end


37
38
39
40
41
42
43
44
45
# File 'lib/qdumpfs/util.rb', line 37

def self.force_symlink(src, dest)
  begin
    File.unlink(dest) if File.anything_exist?(dest)
    File.symlink(src, dest)
  rescue => e      
    puts "force_symlink fails #{src} #{dest} #{e.message}"
#      puts "File.symlink('#{src}', '#{dest}')"
  end
end

.readable_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/qdumpfs/util.rb', line 52

def self.readable_file?(path)
  FileTest.file?(path) and FileTest.readable?(path)
end

.real_directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/qdumpfs/util.rb', line 33

def self.real_directory?(path)
  FileTest.directory?(path) and not FileTest.symlink?(path)
end

.real_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/qdumpfs/util.rb', line 25

def self.real_file?(path)
  FileTest.file?(path) and not FileTest.symlink?(path)
end

.split_all(path) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/qdumpfs/util.rb', line 56

def self.split_all(path)
  parts = []
  while true
    dirname, basename = File.split(path)
    break if path == dirname
    parts.unshift(basename) unless basename == "."
    path = dirname
  end
  return parts
end