Index: /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm =================================================================== --- /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm (revision 17491) +++ /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Misc.pm (working copy) @@ -71,6 +71,12 @@ require Win32::Service; require Win32::Shortcut; } + + if ($^O =~/darwin/i) { + require Mac::Errors; + require Mac::Files; + require Mac::Resources; + } } # Cache our user agent string. @@ -360,6 +366,37 @@ return fixPath(pathFromWinShortcut($shortcut)); } +=head2 pathFromMacAlias( $path ) + +Return the filepath for a given Mac Alias + +=cut + +sub pathFromMacAlias { + my $fullpath = shift; + my $path = ''; + my $log = logger('os.files'); + + if (Slim::Utils::OSDetect::OS() ne "mac") { + + logWarning("Aliases not supported on non-Mac platforms!"); + + return $path; + } + + if (Mac::Resources::FSpOpenResFile($fullpath, 0) && (my $alis = Mac::Resources::GetIndResource('alis', 1))) { + + $path = Mac::Files::ResolveAlias($alis); + + $log->debug("Got path $path from alias $fullpath"); + } + else { + #$log->debug($Mac::Errors::MacError . ": $fullpath"); + } + + return $path; +} + =head2 pathFromFileURL( $url, [ $noCache ]) Given a file::// style url, return the filepath to the caller @@ -872,12 +909,19 @@ # Make sure we can read the file. return 0 if !-r _; + my $target; + # a file can be an Alias on Mac + if (Slim::Utils::OSDetect::OS() eq "mac" && -f _ && $validRE && defined ($target = pathFromMacAlias($fullpath))) { + unless (-d $target) { + return 0; + } + } # Don't bother with file types we don't understand. - if ($validRE && -f _) { + elsif ($validRE && -f _) { return 0 if $item !~ $validRE; } - elsif ($validRE && -l _ && defined(my $target = readlink($fullpath))) { + elsif ($validRE && -l _ && defined($target = readlink($fullpath))) { # fix relative/absolute path $target = ($target =~ /^\// ? $target : catdir($dirname, $target)); Index: /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm =================================================================== --- /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm (revision 17491) +++ /Users/mh/Documents/workspace/trunk/server/Slim/Utils/Scanner.pm (working copy) @@ -173,6 +173,28 @@ } } + elsif (my $file = Slim::Utils::Misc::pathFromMacAlias($file)) { + if (dir($file)->subsumes($topDir)) { + + logWarning("Found an infinite loop! Breaking out: $file -> $topDir"); + next; + } + + # Recurse into additional shortcuts and directories. + if (-d $file) { + + $log->info("Following Mac Alias to: $file"); + + $class->findFilesMatching($file, { + 'foundItems' => $found, + 'recursive' => $args->{'recursive'}, + 'types' => $args->{'types'}, + }); + + next; + } + } + # Fix slashes push @{$found}, File::Spec->canonpath($file); }