Method: FileMonitoring::DirStat#load_symlink

Defined in:
lib/file_monitoring/monitor_path.rb

add symlink while initializing tree using content data from file.

Assumption is that Tree already built

Parameters:

sub_paths - Array of sub paths of the symlink which is added to tree
            Example:
              instance path = /dir1/dir2/file_name
                Sub path 1: /dir1
                Sub path 2: /dir1/dir2
                Sub path 3: /dir1/dir2/file_name
            sub paths would create DirStat objs or FileStat(FileStat create using last sub path).
sub_paths_index - the index indicates the next sub path to insert to the tree
                  the index will be raised at each recursive call down the tree
symlink_path - symlink file path
symlink_target - the target path pointed by the symlink


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/file_monitoring/monitor_path.rb', line 213

def load_symlink(sub_paths, sub_paths_index, symlink_path, symlink_target)
  # initialize dirs and files.
  @dirs = {} unless @dirs
  @files = {} unless @files
  if sub_paths.size-1 == sub_paths_index
    # index points to last entry - leaf case. Add the symlink.
    @symlinks[symlink_path] = symlink_target
  else
    # Add Dir to tree if not present. index points to new dir path.
    dir_stat = @dirs[sub_paths[sub_paths_index]]
    #create new dir if not exist
    unless dir_stat
      dir_stat = DirStat.new(sub_paths[sub_paths_index])
      add_dir(dir_stat)
    end
    # continue recursive call on tree with next sub path index
    dir_stat.load_instance(sub_paths, sub_paths_index+1, symlink_path, symlink_target)
  end
end