[Slim-Checkins] r11784 - /trunk/server/Slim/Utils/Prefs/OldPrefs.pm

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Fri Apr 20 15:48:04 PDT 2007


Author: adrian
Date: Fri Apr 20 15:48:04 2007
New Revision: 11784

URL: http://svn.slimdevices.com?rev=11784&view=rev
Log:
Bug: N/A
Description: additional checks on old preference file before trying to
use it

Modified:
    trunk/server/Slim/Utils/Prefs/OldPrefs.pm

Modified: trunk/server/Slim/Utils/Prefs/OldPrefs.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs/OldPrefs.pm?rev=11784&r1=11783&r2=11784&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs/OldPrefs.pm (original)
+++ trunk/server/Slim/Utils/Prefs/OldPrefs.pm Fri Apr 20 15:48:04 2007
@@ -33,9 +33,7 @@
 	my $class = shift;
 	my $pref  = shift;
 
-	$oldprefs ||= eval { LoadFile(_oldPath()) } || {};
-
-	$oldprefs->{ $pref };
+	$class->_oldPrefs->{ $pref };
 }
 
 =head2 clientGet( $client, $prefname )
@@ -49,9 +47,38 @@
 	my $client = shift;
 	my $pref  = shift;
 
-	$oldprefs ||= eval { LoadFile(_oldPath()) } || {};
+	my $prefs = $class->_oldPrefs;
 
-	$oldprefs->{'clients'}->{ $client->id }->{ $pref } if $oldprefs->{'clients'}->{ $client->id };
+	if ($prefs->{'clients'} && $prefs->{'clients'}->{ $client->id } ) {
+
+		return $prefs->{'clients'}->{ $client->id }->{ $pref };
+	}
+
+	return undef;
+}
+
+sub _oldPrefs {
+	my $class = shift;
+
+	return $oldprefs if $oldprefs;
+
+	if ( my $path = _oldPath() ) {
+
+		$oldprefs = eval { LoadFile($path) };
+
+		if (!$@ && ref $oldprefs eq 'HASH') {
+
+			$log->info("loaded $path");
+
+			return $oldprefs;
+
+		} else {
+
+			$log->warn("failed to load $path [$@]");
+		}
+	}
+
+	return $oldprefs = {};
 }
 
 sub _oldPath {



More information about the checkins mailing list