Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#delete_files_from_dir1_which_exist_in_dir2(delete_from_dir, exist_in_dir) ⇒ Object



6
7
8
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 6

def delete_files_from_dir1_which_exist_in_dir2(delete_from_dir, exist_in_dir)
  run "#{sudo} find #{exist_in_dir} -type f  | xargs -n1 basename | xargs -I{} bash -c 'test -f #{delete_from_dir}/{} && rm -v #{delete_from_dir}/{} || echo no file #{delete_from_dir}/{} to delete'"
end

#mkdir_unless_exists(dir) ⇒ Object



25
26
27
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 25

def mkdir_unless_exists( dir )
  run "test -d #{dir} || #{sudo} mkdir -p #{dir}"
end

#remove_dir_if_exists(dir) ⇒ Object



41
42
43
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 41

def remove_dir_if_exists( dir )
  run "(test -d #{dir} && #{sudo} rm -rf #{dir}) || echo 'no existing #{dir} dir to remove'"
end

#remove_file_if_exists(file) ⇒ Object



37
38
39
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 37

def remove_file_if_exists( file )
  run "(test -f #{file} && #{sudo} rm #{file}) || echo 'no existing #{file} file to remove'"
end

#set_permissions_on_dir(opts) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 45

def set_permissions_on_dir( opts )
  if opts[:ownership]
    run "(test -d #{opts[:dir]} && #{sudo} chown #{opts[:ownership]} ) || echo couldnt find #{opts[:dir]}"
  end
  if opts[:permissions]
    run "(test -d #{opts[:dir]} && #{sudo} chmod #{opts[:permissions]} ) || echo couldnt find #{opts[:dir]}"
  end
end

#set_permissions_on_files_in_dir(opts) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 54

def set_permissions_on_files_in_dir( opts )
  if opts[:ownership]
    run "(test -d #{opts[:dir]} && #{sudo} find #{opts[:dir]} -mindepth 1 | xargs #{sudo} chown #{opts[:ownership]} ) || echo couldnt find #{opts[:dir]}"
  end
  if opts[:permissions]
    run "(test -d #{opts[:dir]} && #{sudo} find #{opts[:dir]} -mindepth 1 | xargs #{sudo} chmod #{opts[:permissions]} ) || echo couldnt find #{opts[:dir]}"
  end
end


2
3
4
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 2

def symlink_dir(from, to)
  run "test -L #{to} || ( #{sudo} find #{to} -mindepth 1 -print | xargs -i mv {} #{from} && #{sudo} rm -rf #{to} && #{sudo} ln -s #{from} #{to} )"
end


10
11
12
13
14
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 10

def symlink_files_in_dir(from_dir,to_dir)  
  delete_files_from_dir1_which_exist_in_dir2(to_dir, from_dir)
  
  run "(#{sudo} test -d #{from_dir} && ( #{sudo} find #{from_dir}/ -mindepth 1  -print | xargs --verbose #{sudo} ln -s -f -t #{to_dir} ) ) || echo 'nothing to link'"
end

Symlinks the files in from_dir matching the regex into the to_dir



19
20
21
22
23
# File 'lib/itrigga/cap_deploy/filesystem_utils.rb', line 19

def symlink_files_in_dir_by_regex(from_dir,to_dir,regex)  
  delete_files_from_dir1_which_exist_in_dir2(to_dir, from_dir)
  
  run "(#{sudo} test -d #{from_dir} && ( #{sudo} find #{from_dir}/ -mindepth 1 -regex '#{regex}' -print | xargs --verbose #{sudo} ln -s -f -t #{to_dir} ) ) || echo 'nothing to link'"
end