Index: bin/gnump3d2 =================================================================== RCS file: /cvsroot/gnump3d/gnump3d/bin/gnump3d2,v retrieving revision 1.84 diff -u -r1.84 gnump3d2 --- bin/gnump3d2 6 Feb 2005 17:06:37 -0000 1.84 +++ bin/gnump3d2 15 Feb 2005 19:28:17 -0000 @@ -63,9 +63,7 @@ # # Global variables # -use vars qw ($main_socket %mime_cache ); - - +use vars qw ($main_socket %mime_cache $reload_cache ); # # @@ -408,8 +406,17 @@ } } - - +# +# Fork into the background if we're supposed to. +# +# NOTE: This won't happen if we're running under '--debug'. +# +if ( ( not $DEBUG ) and ( $BACKGROUND ) ) +{ + fork() && exit; + close(STDOUT); + close(STDERR); +} # # Initialize the song cache - this should be done after the @@ -422,17 +429,10 @@ $tagCache->setHideTags( $hide_song_tags ); # -# Fork into the background if we're supposed to. +# Reload cache if given SIGHUP. # -# NOTE: This won't happen if we're running under '--debug'. -# -if ( ( not $DEBUG ) and ( $BACKGROUND ) ) -{ - fork() && exit; - close(STDOUT); - close(STDERR); -} - +$reload_cache = 0; +$SIG{HUP} = sub { $reload_cache = 1; }; # # Make sure that all our errors and output go to the error @@ -1179,6 +1179,12 @@ # # Parent from the fork(); # + # Reload the tag cache if we were instructed to. + if ($reload_cache) { + $tagCache->setCacheFile( $tag_cache ); + $reload_cache = 0; + } + exit; } @@ -1401,7 +1407,6 @@ # Song tags if any. my $tags = ""; - # # Sort the files according to the display preference. # @@ -1785,7 +1790,7 @@ my $writecache = 0; my $pre_exit; - + if (!(-e "$down_cachedir/$cacheFile.full" && open (SAMPLE, "$down_cachedir/$cacheFile.full"))) { opendir(CACHECHECK, $down_cachedir); my $cachesize = 0; @@ -2095,6 +2100,7 @@ print -M "$dir/$file"; print "\n"; +# XXXXXX if ( ( -M $dir . "/" . $file ) < $new_days ) { $row =~ s/\$NEW/$new_format/g; @@ -2103,7 +2109,7 @@ { $row =~ s/\$NEW//g; } - + # # Only calculate the number of songs if necessary. # Optimization. @@ -2256,7 +2262,7 @@ # # This is a speed optimization, rather than fetching each # song detail from the cache we pull them out en masse, - # leaving use with a HASH. + # leaving us with a HASH. # # The hash has keys of filenames, and values of the # tags to be displayed. @@ -2338,7 +2344,7 @@ # # Do the interpolation. my $output; - + if ( $totalPlaylists % 2 == 0 ) { $output = $file_format; @@ -2421,7 +2427,6 @@ } - # # Build up the text to insert into the file lists. # Index: lib/gnump3d/tagcache.pm =================================================================== RCS file: /cvsroot/gnump3d/gnump3d/lib/gnump3d/tagcache.pm,v retrieving revision 1.9 diff -u -r1.9 tagcache.pm --- lib/gnump3d/tagcache.pm 14 Jan 2005 20:17:20 -0000 1.9 +++ lib/gnump3d/tagcache.pm 15 Feb 2005 19:28:17 -0000 @@ -147,11 +147,20 @@ foreach () { + my %TAGS; chomp; $count++; my @NAMES = split( /\t/, $_); my $file = shift(@NAMES); - $CACHE{$file} = address@hidden; + foreach my $pair ( @NAMES ) + { + if ( ( $pair =~ /([A-Z]+)=(.*)/ ) && + ( length( $2 ) ) ) + { + $TAGS{ $1 } = $2; + } + } + $CACHE{$file} = \%TAGS; } close( FILY ); if ($count > 0) @@ -178,14 +187,6 @@ # my %RESULTS; - # Check to see if the cache file has been updated. if it has, re-load it. - my @finfo = stat($CACHE_FILE); - if ($finfo[10] > $FILE_MOD) - { - print "Tag cache file changed on disk, re-loading\n"; - $self->setCacheFile($CACHE_FILE); - } - # # Now find the tags for each file, and format them # @@ -241,15 +242,7 @@ if (exists($CACHE{$file})) { - my $NAMES = $CACHE{$file}; - foreach my $pair ( @$NAMES ) - { - if ( ( $pair =~ /([A-Z]+)=(.*)/ ) && - ( length( $2 ) ) ) - { - $TAGS{ $1 } = $2; - } - } + %TAGS = %{$CACHE{$file}}; # Convert the file size to something more # readable @@ -329,20 +322,14 @@ $TAGS{'TRACK'} = $tags{'track'} || ""; $TAGS{'ALBUM'} = $tags{'album'} || ""; $TAGS{'TITLE'} = $tags{'title'} || ""; - $TAGS{'YEAR'} = $tags{'year'} || ""; - + $TAGS{'YEAR'} = $tags{'year'} || ""; } } # And now, store the results in the cache so we don't have # to look it up again. - - - my @NAMES = (); - foreach (keys(%TAGS)) { - push(@NAMES, $_ . "=" . $TAGS{$_}); - } - $CACHE{$file} = address@hidden; + $CACHE{$file} = \%TAGS; + # XXXXX STORE ME IN CACHE AND/OR MARK FOR ADDITION. } # @@ -413,6 +400,7 @@ # # Make sure we have 'real' tags found. # + my $valid = 0; foreach my $key ( keys %TAGS ) { @@ -428,7 +416,10 @@ next if ( $key eq 'UPPER' ); next if ( $key eq 'VERSION' ); next if ( $key eq 'WINDOW' ); - $valid += 1; + next if ( $key eq 'mtime' ); + next if ( $TAGS{"$key"} eq '' ); # tag cache can have "empty" tags. + + $valid++; } @@ -506,7 +497,7 @@ =item C -Specify the name of the cache file to read when formatting tags. If a cache file has previously been specified and read its contents will be discarded. +Specify the name of the cache file to read when formatting tags. If a cache file has previously been specified this will be used instead. =item C @@ -517,8 +508,6 @@ Obtain and format the song tags for a collection of files, this is massively faster than doing the same operation on a single file. - - =back =head1 AUTHOR