Module: Motion::FileUtils

Defined in:
lib/project/motion-fileutils.rb

Class Method Summary collapse

Class Method Details

.cp(src, dest, options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/project/motion-fileutils.rb', line 104

def cp(src, dest, options = {})
  error = Pointer.new(:object)
  m = NSFileManager.defaultManager
  if File.file?(dest) || !File.exists?(dest)
    raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest)
    rm dest if File.file?(dest)
    r = m.copyItemAtPath src, toPath:dest, error:error
#p error, r unless r
  else
    src = [src] unless src.is_a? Array
    src.each do |path|
      r = m.copyItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error
#p error, r unless r
    end
  end
end

.makedirsObject



22
23
24
# File 'lib/project/motion-fileutils.rb', line 22

def mkdir_p(dir, options = {})
  mkdir_with_intermediate(dir, true, options)
end

.mkdir(dir, options = {}) ⇒ Object



9
10
11
# File 'lib/project/motion-fileutils.rb', line 9

def mkdir(dir, options = {})
  mkdir_with_intermediate(dir, false, options)
end

.mkdir_p(dir, options = {}) ⇒ Object



14
15
16
# File 'lib/project/motion-fileutils.rb', line 14

def mkdir_p(dir, options = {})
  mkdir_with_intermediate(dir, true, options)
end

.mkpathObject



19
20
21
# File 'lib/project/motion-fileutils.rb', line 19

def mkdir_p(dir, options = {})
  mkdir_with_intermediate(dir, true, options)
end

.moveObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/project/motion-fileutils.rb', line 101

def mv(src, dest, options = {})
  error = Pointer.new(:object)
  m = NSFileManager.defaultManager
  if File.file?(dest) || !File.exists?(dest)
    raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest)
    rm dest if File.file?(dest)
    r = m.moveItemAtPath src, toPath:dest, error:error
#p error, r unless r
  else
    src = [src] unless src.is_a? Array
    src.each do |path|
      r = m.moveItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error
#p error, r unless r
    end
  end
end

.mv(src, dest, options = {}) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/project/motion-fileutils.rb', line 83

def mv(src, dest, options = {})
  error = Pointer.new(:object)
  m = NSFileManager.defaultManager
  if File.file?(dest) || !File.exists?(dest)
    raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest)
    rm dest if File.file?(dest)
    r = m.moveItemAtPath src, toPath:dest, error:error
#p error, r unless r
  else
    src = [src] unless src.is_a? Array
    src.each do |path|
      r = m.moveItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error
#p error, r unless r
    end
  end
end

.private_module_function(name) ⇒ Object

:nodoc:



4
5
6
7
# File 'lib/project/motion-fileutils.rb', line 4

def self.private_module_function(name)   #:nodoc:
  module_function name
  private_class_method name
end

.removeObject



36
37
38
39
40
41
42
43
44
# File 'lib/project/motion-fileutils.rb', line 36

def rm(list, options = {})
  error = Pointer.new(:object)
  m = NSFileManager.defaultManager
  list = [list] unless list.is_a? Array
  list.each do |path|
    r = m.removeItemAtPath path, error:error
#p error, r unless r
  end
end

.rm(list, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/project/motion-fileutils.rb', line 25

def rm(list, options = {})
  error = Pointer.new(:object)
  m = NSFileManager.defaultManager
  list = [list] unless list.is_a? Array
  list.each do |path|
    r = m.removeItemAtPath path, error:error
#p error, r unless r
  end
end

.touch(list, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/project/motion-fileutils.rb', line 63

def touch(list, options = {})
  t = options[:mtime]
  created = nocreate = options[:nocreate]
  list = [list] unless list.is_a? Array
  list.each do |path|
    begin
      File.utime(t, t, path)
    rescue Errno::ENOENT
      raise if created
      File.open(path, 'a') {
        ;
      }
      created = true
      retry if t
    end
  end
end