Last active
November 14, 2017 18:51
-
-
Save lefth/6d71ca714ca2dc184220a91ceb41334d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
# I run this in a directory with 30k files. | |
# I suggest using a SSD if you have one, for your sanity. | |
use v6; | |
sub gather-files(Str $start-path --> List) { | |
# Gather a list of all files. Run this is a huge directory. | |
my $files = Channel.new; | |
my IO @dirs = ($start-path.IO); | |
while (@dirs) | |
{ | |
@dirs = @dirs.race.map(-> $dir { | |
#@dirs = @dirs.map(-> $dir { | |
|$dir.dir.race.map( -> IO $path { | |
#|$dir.dir.map( -> IO $path { | |
if ($path.d) { | |
$path; | |
} else { | |
if (!$path.l) { | |
$files.send: $path.Str; | |
} | |
|(); # slip nothing into the list | |
} | |
}); | |
}); | |
} | |
$files.close; | |
return $files.list; | |
} | |
sub MAIN(Str $start-path='.') { | |
my @files = gather-files($start-path); | |
my $stop = False; | |
await do for @files -> $file-path { | |
last if $stop; | |
start { | |
$file-path.IO.slurp; | |
#my $fh = $file-path.IO.open: :r; | |
#$fh.lines.cache; | |
#$fh.close; | |
CATCH { | |
when / 'UTF-8' / { } # we don't care about UTF-8 exceptions | |
default { | |
note "Got exception: $_"~.backtrace.full; | |
$stop = True; | |
} | |
} | |
} | |
} | |
die if $stop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment