Class: EventMachine::FileUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/em-fs/fileutils.rb

Class Method Summary collapse

Class Method Details

.chmod(mode, *dest, &block) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/em-fs/fileutils.rb', line 115

def chmod mode, *dest, &block
  options = { recursive: false }.merge dest.extract_options!
  cmd = EM::SystemCommand.new 'chmod'
  cmd << :R if options[:recursive]
  cmd << mode << dest
  cmd.execute &block
end

.chmod_R(mode, *dest, &block) ⇒ Object



123
124
125
126
# File 'lib/em-fs/fileutils.rb', line 123

def chmod_R mode, *dest, &block
  options = { recursive: false }.merge dest.extract_options!
  chmod mode, *dest, options.merge(recursive: true), &block
end

.chown(user, group, *dest, &block) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/em-fs/fileutils.rb', line 128

def chown user, group, *dest, &block
  options = { recursive: false }.merge dest.extract_options!
  cmd = EM::SystemCommand.new 'chown'
  cmd << :R if options[:recursive]
  cmd << "#{user.to_s}:#{group.to_s}" << dest
  cmd.execute &block
end

.chown_R(user, group, *dest, &block) ⇒ Object



136
137
138
139
# File 'lib/em-fs/fileutils.rb', line 136

def chown_R user, group, *dest, &block
  options = { recursive: false }.merge dest.extract_options!
  chown user, group, dest, options.merge(recursive: true), &block
end

.cp(*args, &block) ⇒ Object

Copy files.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/em-fs/fileutils.rb', line 56

def cp *args, &block
  options = { recursive: false }.merge args.extract_options!
  unless args.length >= 2
    raise 'Too few arguments. Need source and destination at least.'
  end

  cmd = EM::SystemCommand.new 'cp'
  cmd << :r if options[:recursive]
  cmd << args
  cmd.execute &block
end

.cp_r(*args, &block) ⇒ Object

Recursively copy files.



70
71
72
73
# File 'lib/em-fs/fileutils.rb', line 70

def cp_r *args, &block
  options = { recursive: false }.merge args.extract_options!
  cp *args, options.merge(recursive: true), &block
end

.install(*args, &block) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/em-fs/fileutils.rb', line 107

def install *args, &block
  options = { mode: '755' }.merge args.extract_options!
  cmd = EM::SystemCommand.new 'install'
  cmd.add '--mode', options[:mode] if options[:mode]
  cmd << args
  cmd.execute &block
end

.ln(src, dest, options = {}, &block) ⇒ Object

Create link in file system.



33
34
35
36
37
38
39
40
# File 'lib/em-fs/fileutils.rb', line 33

def ln src, dest, options = {}, &block
  options = { symbolic: false, force: false }.merge options
  cmd = EM::SystemCommand.new 'ln'
  cmd << :s if options[:symbolic]
  cmd << :f if options[:force]
  cmd << src << dest
  cmd.execute &block
end

.ln_s(src, dest, options = {}, &block) ⇒ Object

Create symbolic link.



44
45
46
# File 'lib/em-fs/fileutils.rb', line 44

def ln_s src, dest, options = {}, &block
  ln src, dest, options.merge(symbolic: true), &block
end

.ln_sf(src, dest, options = {}, &block) ⇒ Object

Force symbolic link creation.



50
51
52
# File 'lib/em-fs/fileutils.rb', line 50

def ln_sf src, dest, options = {}, &block
  ln src, dest, options.merge(symbolic: true, force: true), &block
end

.mkdir(*dirs, &block) ⇒ Object

Make directories.



6
7
8
9
10
11
12
# File 'lib/em-fs/fileutils.rb', line 6

def mkdir *dirs, &block
  options = { parents: false }.merge dirs.extract_options!
  cmd = EM::SystemCommand.new 'mkdir', &block
  cmd << :p if options[:parents]
  cmd << dirs
  cmd.execute
end

.mkdir_p(*dirs, &block) ⇒ Object

Make directories with parents.



16
17
18
19
# File 'lib/em-fs/fileutils.rb', line 16

def mkdir_p *dirs, &block
  options = {}.merge dirs.extract_options!
  mkdir *dirs, options.merge(parents: true), &block
end

.mv(*args, &block) ⇒ Object

Move files or directories.



77
78
79
80
81
82
83
84
85
86
# File 'lib/em-fs/fileutils.rb', line 77

def mv *args, &block
  options = { recursive: false }.merge args.extract_options!
  unless args.length >= 2
    raise 'Too few arguments. Need source and destination at least.'
  end

  cmd = EM::SystemCommand.new 'mv'
  cmd << args
  cmd.execute &block
end

.rm(*args, &block) ⇒ Object

Remove files or directories.



90
91
92
93
94
95
96
97
# File 'lib/em-fs/fileutils.rb', line 90

def rm *args, &block
  options = { recursive: false, force: false }.merge args.extract_options!
  cmd = EM::SystemCommand.new 'rm'
  cmd << '-r' if options[:recursive]
  cmd << '-f' if options[:force]
  cmd << args
  cmd.execute &block
end

.rm_r(target, options = {}, &block) ⇒ Object



99
100
101
# File 'lib/em-fs/fileutils.rb', line 99

def rm_r target, options = {}, &block
  rm target, options.merge(recursive: true), &block
end

.rm_rf(target, options = {}, &block) ⇒ Object



103
104
105
# File 'lib/em-fs/fileutils.rb', line 103

def rm_rf target, options = {}, &block
  rm target, options.merge(recursive: true, force: true), &block
end

.rmdir(*dirs, &block) ⇒ Object

Remove the directories if they are empty.



23
24
25
26
27
28
29
# File 'lib/em-fs/fileutils.rb', line 23

def rmdir *dirs, &block
  options = { parents: false }.merge dirs.extract_options!
  cmd = EM::SystemCommand.new 'rmdir'
  cmd << :p if options[:parents]
  cmd << dirs
  cmd.execute &block
end

.touch(*dest, &block) ⇒ Object



141
142
143
144
145
146
# File 'lib/em-fs/fileutils.rb', line 141

def touch *dest, &block
  options = {}.merge dest.extract_options!
  cmd = EM::SystemCommand.new 'touch'
  cmd << dest
  cmd.execute &block
end