class RBT::RemoveSymlinks
Constants
- ARRAY_DIRECTORIES_TO_CHECK
#¶ ↑
ARRAY_DIRECTORIES_TO_CHECK
¶ ↑#¶ ↑
- DEFAULT_MODE
#¶ ↑
DEFAULT_MODE
¶ ↑#¶ ↑
- SHALL_WE_CREATE_MISSING_DIRECTORIES
#¶ ↑
SHALL_WE_CREATE_MISSING_DIRECTORIES
¶ ↑This may create missing directories.
#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
consider_using_other_directories()
click to toggle source
#¶ ↑
consider_using_other_directories
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 178 def consider_using_other_directories case @mode when 'HERE','PWD','pwd' # This allows us to work on the current directory instead. @array_directories_to_check[0,0] = return_pwd end unless File.exist? @mode end
get_all_symlinks_from( i = return_pwd, be_verbose = true )
click to toggle source
#¶ ↑
get_all_symlinks_from
¶ ↑
This method will fetch and then return all symlinks from a given directory.
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 142 def get_all_symlinks_from( i = return_pwd, be_verbose = true ) set_base_dir(i) _ = Dir["#{@base_dir}*"].reject {|file| ! File.symlink? file} if be_verbose opne "#{rev}There are #{sfancy(_.size.to_s.rjust(3))} "\ "#{rev}symlinks listed in #{sdir(i)}#{rev}." end return _ end
notify_the_user_how_many_symlinks_were_removed()
click to toggle source
#¶ ↑
notify_the_user_how_many_symlinks_were_removed
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 157 def notify_the_user_how_many_symlinks_were_removed _ = @array_remove_these_broken_symlinks unless _.empty? opne "#{rev}We were able to remove "\ "#{orange(_.size.to_s)} #{rev}non-existing symlinks." end end
process_each_directory( i = @array_directories_to_check )
click to toggle source
#¶ ↑
process_each_directory
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 105 def process_each_directory( i = @array_directories_to_check ) unless i.is_a? Array i = [i] end i.each {|entry| unless File.exist? entry if SHALL_WE_CREATE_MISSING_DIRECTORIES opnwarn "#{rev}#{swarn('The directory `')}"\ "#{sdir(entry)}#{swarn('` does not exist.')}" opnwarn 'Thus, we will create it now.' create_directory(entry) end end # ===================================================================== # # Next, obtain all symlinks from the target. # ===================================================================== # _ = get_all_symlinks_from(entry) _.each {|inner_entry| if File.exist? inner_entry # File exist, this is good, passthrough. else # The file does not exist, so register it for removal. # e 'FILE DOES NOT EXIST '+sfile(inner_entry) opne "#{sfile(inner_entry)}#{rev} does not exist." opne "#{rev}→ Thus we delete `#{sfile(inner_entry)}#{rev}`." register_broken_symlink_for_removal(inner_entry) # First register, then delete. end } } end
register_broken_symlink_for_removal(i)
click to toggle source
remove_all_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet )
click to toggle source
#¶ ↑
remove_all_symlinks
¶ ↑
This method will remove all symlinks in the current directory.
Invocation examples:
remove_symlinks --remove-all-symlinks remove_symlinks --pwd
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 265 def remove_all_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet ) _ = these_entries.select {|entry| File.symlink? entry } delete_symlink(_, be_verbose) end
Also aliased as: remove_these_symlinks
remove_broken_symlinks()
click to toggle source
#¶ ↑
remove_broken_symlinks
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 206 def remove_broken_symlinks if @array_remove_these_broken_symlinks.empty? opne 'We did not find any broken symlinks on the system. '\ 'This is good!' else @array_remove_these_broken_symlinks.each {|this_symlink| # =================================================================== # # The reason we handle it in this class is so that we # can use opnn() on each removed symlink. # =================================================================== # opnn; delete_symlink(this_symlink, :be_verbose) } end end
remove_empty_directories()
click to toggle source
#¶ ↑
remove_empty_directories
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 168 def remove_empty_directories # ======================================================================= # # Delegate towards class RBT::RemoveEmptyDirectories next: # ======================================================================= # RemoveEmptyDirectories.new end
remove_these_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet )
Alias for: remove_all_symlinks
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 67 def reset super() infer_the_namespace # ======================================================================= # # === @array_directories_to_check # ======================================================================= # @array_directories_to_check = ARRAY_DIRECTORIES_TO_CHECK # ======================================================================= # # === @array_remove_these_broken_symlinks # ======================================================================= # @array_remove_these_broken_symlinks = [] # ======================================================================= # # === :be_verbose # ======================================================================= # set_be_quiet end
run()
click to toggle source
set_base_dir(i)
click to toggle source
set_mode( i = DEFAULT_MODE )
click to toggle source
#¶ ↑
set_mode
¶ ↑
Not yet sure if we need this.
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 226 def set_mode( i = DEFAULT_MODE ) if i.is_a? Array i = i.first end i = DEFAULT_MODE if i.nil? case i # case tag # ======================================================================= # # === remove_symlinks --pwd # # This entry point will use the current working directory as our # input-base. # ======================================================================= # when /^-?-?pwd$/, /^-?-?remove(-|_)?all(-|_)?symlinks$/ remove_these_symlinks(Dir['*'], :be_verbose) exit # ======================================================================= # # === remove_symlinks --help # ======================================================================= # when /^-?-?help$/ show_help exit end @mode = i.to_s # Will be guaranteed to be a String. end
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
To invoke this method, try:
remove_symlinks --help
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 193 def show_help opnn { :no_trailing_character } e e e ' --remove-all-symlinks # Remove all symlinks in '\ 'the current directory.' e ' --pwd # ^^^ an alias to the above' e end