Index: /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm =================================================================== --- /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm (revision 15455) +++ /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm (working copy) @@ -830,6 +830,68 @@ $_ignoredItems{'..'} = 1; +=head2 fileFilter( $dirname, $item ) + + Verify whether we want to include a file or folder in our search. + This helper function is used to guarantee identical filtering across + different browse/scan procedures + +=cut + +sub fileFilter { + my $dirname = shift; + my $item = shift; + my $validRE = shift || Slim::Music::Info::validTypeExtensions(); + + return 0 if exists $_ignoredItems{$item}; + + # Ignore special named files and directories + # __ is a match against our old __history and __mac playlists. + # ._Foo is a OS X meta file. + return 0 if $item =~ /^__\S+\.m3u$/o; + return 0 if $item =~ /^\./o; + + if ((my $ignore = $prefs->get('ignoreDirRE') || '') ne '') { + return 0 if $item =~ /$ignore/; + } + + my $fullpath = catdir($dirname, $item); + + # Don't display hidden/system files on Windows + if (Slim::Utils::OSDetect::OS() eq "win") { + my $attributes; + Win32::File::GetAttributes($fullpath, $attributes); + return 0 if ($attributes & Win32::File::HIDDEN()) || ($attributes & Win32::File::SYSTEM()); + } + + + # We only want files, directories and symlinks Bug #441 + # Otherwise we'll try and read them, and bad things will happen. + # symlink must come first so an lstat() is done. + return 0 unless (-l $fullpath || -d _ || -f _); + + + # Make sure we can read the file. + return 0 if !-r _; + + + # Don't bother with file types we don't understand. + if ($validRE && -f _) { + return 0 if $item !~ $validRE; + } + elsif ($validRE && -l _ && defined(my $target = readlink($fullpath))) { + # fix relative/absolute path + $target = ($target =~ /^\// ? $target : catdir($dirname, $target)); + + if (-f $target) { + return 0 if $target !~ $validRE; + } + } + + return 1 +} + + =head2 readDirectory( $dirname, [ $validRE ]) Return the contents of a directory $dirname as an array. Optionally return only @@ -843,8 +905,6 @@ my @diritems = (); my $log = logger('os.files'); - my $ignore = $prefs->get('ignoreDirRE') || ''; - if (Slim::Utils::OSDetect::OS() eq 'win') { my ($volume) = splitpath($dirname); @@ -867,49 +927,6 @@ for my $item (readdir(DIR)) { - next if exists $_ignoredItems{$item}; - - # Ignore special named files and directories - # __ is a match against our old __history and __mac playlists. - # ._Foo is a OS X meta file. - next if $item =~ /^__\S+\.m3u$/; - next if $item =~ /^\./; - - if ($ignore ne '') { - next if $item =~ /$ignore/; - } - - my $fullpath = catdir($dirname, $item); - - # Don't display hidden/system files on Windows - if (Slim::Utils::OSDetect::OS() eq "win") { - my $attributes; - Win32::File::GetAttributes($fullpath, $attributes); - next if ($attributes & Win32::File::HIDDEN()) || ($attributes & Win32::File::SYSTEM()); - } - - - # We only want files, directories and symlinks Bug #441 - # Otherwise we'll try and read them, and bad things will happen. - # symlink must come first so an lstat() is done. - unless (-l $fullpath || -d _ || -f _) { - next; - } - - - # Don't bother with file types we don't understand. - if ($validRE && -f _) { - next unless $item =~ $validRE; - } - elsif ($validRE && -l _ && defined(my $target = readlink($fullpath))) { - # fix relative/absolute path - $target = ($target =~ /^\// ? $target : catdir($dirname, $target)); - - if (-f $target) { - next unless $target =~ $validRE; - } - } - # call idle streams to service timers - used for blocking animation. if (scalar @diritems % 3) { main::idleStreams(); @@ -915,6 +932,8 @@ main::idleStreams(); } + next unless fileFilter($dirname, $item, $validRE); + push @diritems, $item; } Index: /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm =================================================================== --- /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm (revision 15454) +++ /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm (working copy) @@ -129,26 +129,7 @@ }; my $file_filter = sub { - - # validTypeExtensions returns a qr// regex. - return 0 if $_ !~ $types; - - # Make sure we can read the file. - return 0 if !-r $File::Next::name; - - # Don't include old style internal playlists. - return 0 if /^__\S+\.m3u$/o; - - # OS X leaves around turd files - ignore them. - return 0 if /^\.Apple(?:Single|Double)$/io; - - # iTunes 4.x makes binary metadata files with the format of: ._filename.ext - # In the same directory as the real audio files. Ignore those, so we - # don't create bogus tracks and try to guess names based off the file, - # thus duplicating tracks & albums, etc. - return 0 if /^\._/o; - - return 1; + return Slim::Utils::Misc::fileFilter($File::Next::dir, $_, $types); }; my $iter = File::Next::files({