Class: File

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

Class Method Summary collapse

Class Method Details

.generic_transfer(old_name, new_name, method) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/miga.rb', line 63

def self.generic_transfer(old_name, new_name, method)
   return nil if exist? new_name
   case method
   when :symlink
	 File.symlink(old_name, new_name)
   when :hardlink
	 File.link(old_name, new_name)
   when :copy
	 FileUtils.cp_r(old_name, new_name)
   else
	 raise "Unknown transfer method: #{method}."
   end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/miga.rb', line 49

def self.unlink_r(path)
   if Dir.exists? path
	 unless File.symlink? path
  Dir.entries(path).reject{|f| f =~ /^\.\.?$/}.each do |f|
     File.unlink_r path + "/" + f
  end
	 end
	 Dir.unlink path
   elsif File.exists? path
	 File.unlink path
   else
	 raise "Cannot find file: #{path}"
   end
end