From: Chris Koeritz Date: Mon, 6 Nov 2017 03:37:50 +0000 (-0500) Subject: closer to recursive alias additions X-Git-Tag: 2.140.90~67 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=ee2fb4644decc82b23d54e48c298b45ec042d123;p=feisty_meow.git closer to recursive alias additions at least this version seems as good as it was, if not better. but we're not going deep yet. --- diff --git a/scripts/core/generate_aliases.pl b/scripts/core/generate_aliases.pl index 2f87acc0..20d5bd96 100644 --- a/scripts/core/generate_aliases.pl +++ b/scripts/core/generate_aliases.pl @@ -61,14 +61,6 @@ sub make_perl_alias { print she "define_yeti_alias $aliasname=\"perl $source_dir/$full_alias.pl\"\n"; } -# given a directory, this returns an array of all the filenames found therein. -sub load_file_names { - local($path) = shift(@_); - opendir(that_dir, $path); - local(@those_files) = sort(readdir(that_dir)); - return @those_files; -} - ############## # The "common.alias" file is used in the generated aliases file as a base @@ -196,8 +188,12 @@ open(she, ">> $FEISTY_MEOW_LOADING_DOCK/fmc_aliases_for_scripts.sh"); #@shell_files = sort(readdir(scripts)); #print "scripts: @shell_files\n"; -@shell_files = (&load_file_names("$FEISTY_MEOW_SCRIPTS"), - &load_file_names("$FEISTY_MEOW_LOADING_DOCK/custom/scripts")); +@shell_files = (&find_files("$FEISTY_MEOW_SCRIPTS"), + &find_files("$FEISTY_MEOW_LOADING_DOCK/custom/scripts"), + &find_files(find_directories("$FEISTY_MEOW_LOADING_DOCK/custom/scripts"))); +#really want the recursive one called here, but baby steps + +printf "found all these files: @shell_files\n"; # construct aliases for items in the scripts directory. foreach $file (@shell_files) { @@ -246,7 +242,7 @@ foreach $file (@shell_files) { # open the source repository's script directory to find scripts in there. local($build_shell_path) = "$BUILD_TOP/scripts/generator"; -@build_shells = &load_file_names("$build_shell_path"); +@build_shells = &find_files("$build_shell_path"); #opendir(build_shells_dir, $build_shell_path); #@build_shell_files = sort(readdir(build_shells_dir)); #if (scalar(@build_shell_files) > 0) { diff --git a/scripts/files/filename_helper.pl b/scripts/files/filename_helper.pl index 4117df89..2205cf96 100644 --- a/scripts/files/filename_helper.pl +++ b/scripts/files/filename_helper.pl @@ -400,26 +400,119 @@ sub upper { # recursively deletes a directory that is passed as the single parameter. # from http://developer.novell.com/wiki/index.php/Recursive_Directory_Remove sub recursive_delete { - -#hmmm: this should iterate across all params. - my $dir = shift; - - if ( -f "$dir" ) { + my $dir; + foreach $dir (@_) { + if ( -f "$dir" ) { print "this is not a dir: $dir\nshould whack it here?\n"; return; + } + + local *DIR; + opendir DIR, $dir or die "opendir $dir: $!"; + while ($_ = readdir DIR) { + next if /^\.{1,2}$/; + my $path = "$dir/$_"; + unlink $path if -f $path; + recursive_delete($path) if -d $path; + } + closedir DIR; + rmdir $dir or print "error - $!"; + } +} + +############################################################################ + +# finds any directories under the arguments, which can be a list of directories. +sub find_directories { + my @dirs_found = (); + my $dir; + foreach $dir (@_) { +printf "FD outer dir: $dir\n"; + local *DIR; + opendir DIR, $dir or die "opendir $dir: $!"; + while ($_ = readdir DIR) { + # skip if it's current or parent dir. + next if /^\.{1,2}$/; + my $path = "$dir/$_"; + # skip if this entry is not itself a directory. + next if ! -d $path; +printf "FD adding $path to our list.\n"; + push @dirs_found, $path; + } + closedir DIR; + } + return @dirs_found; +} + +############################################################################ + +# given a directory, this returns an array of all the filenames found therein. +sub find_files { + my @files_found = (); + my $dir; + foreach $dir (@_) { +#printf "LFN outer dir: $dir\n"; + local *DIR; + opendir DIR, $dir or die "opendir $dir: $!"; + while ($_ = readdir DIR) { + # skip if it's current or parent dir. + next if /^\.{1,2}$/; + my $path = "$dir/$_"; + # skip if this entry is not a file. + next if ! -f $path; +#printf "LFN adding $path to our list.\n"; + push @files_found, $path; + } + closedir DIR; } + return @files_found; +} - local *DIR; - opendir DIR, $dir or die "opendir $dir: $!"; - my $found = 0; - while ($_ = readdir DIR) { - next if /^\.{1,2}$/; - my $path = "$dir/$_"; - unlink $path if -f $path; - recursive_delete($path) if -d $path; +############################################################################ + +# finds all directories starting at a particular directory and returns them +# in an array. does not include the starting directory. +sub recursive_find_directories { + +#fix this + +#flush not working! +$|++; + my @dir_list = @_; +printf "got into find dirs, args are: @dir_list\n"; + my @to_return = (); + my $dir; + foreach $dir (@dir_list) { +printf "outer dir: $dir\n"; + local *DIR; + opendir DIR, $dir or die "opendir $dir: $!"; + while ($_ = readdir DIR) { + # skip if it's current or parent dir. + next if /^\.{1,2}$/; + my $path = "$dir/$_"; + # skip if this entry is not itself a directory. + next if ! -d $path; + # add to our list if it's a directory. +printf "adding $path to our list.\n"; + push @to_return, $path; +#this isn't needed, right???? + next; + } + closedir DIR; } - closedir DIR; - rmdir $dir or print "error - $!"; + +printf "list before recursion: @to_return\n"; + + # return the composition of the list we found here plus any directories under those. +#hmmm: this is hideous! it will just grow greater. can't we do this efficiently? + +#hmmm: this causes things to totally fail. what is going on??? + my @subs_found ; +@subs_found = recursive_find_directories(@to_return); + + push(@to_return, @subs_found); + + return @to_return; } ############################################################################