[Slim-Checkins] r11776 - in /trunk/server: Slim/Utils/Prefs.pm Slim/Utils/Prefs/Base.pm Slim/Utils/Prefs/Namespace.pm Slim/Utils/Prefs/OldPrefs.pm scanner.pl

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Tue Apr 17 14:51:46 PDT 2007


Author: adrian
Date: Tue Apr 17 14:51:45 2007
New Revision: 11776

URL: http://svn.slimdevices.com?rev=11776&view=rev
Log:
Bug: N/A
Description: prefs updates:
- ability to make a namespace read only - used within scanner to
protect against accidentially setting prefs
- suppress warnings from Slim::Control::Request::__parse during
migration due to notifies being called prior to init for dispatchDB
- try harder to find old preference file

Modified:
    trunk/server/Slim/Utils/Prefs.pm
    trunk/server/Slim/Utils/Prefs/Base.pm
    trunk/server/Slim/Utils/Prefs/Namespace.pm
    trunk/server/Slim/Utils/Prefs/OldPrefs.pm
    trunk/server/scanner.pl

Modified: trunk/server/Slim/Utils/Prefs.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs.pm?rev=11776&r1=11775&r2=11776&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs.pm (original)
+++ trunk/server/Slim/Utils/Prefs.pm Tue Apr 17 14:51:45 2007
@@ -1428,6 +1428,12 @@
 		'thumbSize'             => 100,
 	);
 
+	# add entry to dispatch table if it is loaded (it isn't in scanner.pl) as migration may call notify for this
+	# this is required as Slim::Control::Request::init will not have run at this point
+	if (exists &Slim::Control::Request::addDispatch) {
+		Slim::Control::Request::addDispatch(['prefset'], [0, 0, 1, undef]);
+	}
+
 	# migrate old prefs across
 	$prefs->migrate(1, sub {
 		unless (-d $path) { mkdir $path; }

Modified: trunk/server/Slim/Utils/Prefs/Base.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs/Base.pm?rev=11776&r1=11775&r2=11776&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs/Base.pm (original)
+++ trunk/server/Slim/Utils/Prefs/Base.pm Tue Apr 17 14:51:45 2007
@@ -72,11 +72,19 @@
 
 	my $root  = $class->_root;
 	my $change = $root->{'onchange'}->{ $pref };
+	my $readonly  = $root->{'readonly'};
 	my $validator = $root->{'validators'}->{ $pref };
 	my $namespace = $root->{'namespace'};
 	my $clientid  = $class->{'clientid'} || '';
 
 	my $valid  = $validator ? $validator->($pref, $new, $root->{'validparams'}->{ $pref }, $old, $class->_obj) : 1;
+
+	if ($readonly) {
+
+		logBacktrace(sprintf "attempt to set %s:%s:%s while namespace is readonly", $namespace, $clientid, $pref);
+
+		return wantarray ? ($old, 0) : $old;
+	}
 
 	if ($valid && $pref !~ /^_/) {
 

Modified: trunk/server/Slim/Utils/Prefs/Namespace.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs/Namespace.pm?rev=11776&r1=11775&r2=11776&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs/Namespace.pm (original)
+++ trunk/server/Slim/Utils/Prefs/Namespace.pm Tue Apr 17 14:51:45 2007
@@ -69,6 +69,7 @@
 	my $class = bless {
 		'namespace' => $namespace,
 		'file'      => $filename,
+		'readonly'  => 0,
 		'clients'   => {},
 		'validators'=> {},
 		'validparam'=> {},
@@ -128,7 +129,7 @@
 	}
 }
 
-=head2 setchange( $callback, list )
+=head2 setChange( $callback, list )
 
 Associates callback function $callback with the preferences listed by list.
 
@@ -180,6 +181,19 @@
 	}
 
 	return $prefs;
+}
+
+=head2 readonly( )
+
+Sets this namespace to readonly.
+
+=cut
+
+sub readonly {
+	my $class  = shift;
+	my $flag   = shift;
+
+	$class->{'readonly'} = 1;
 }
 
 =head2 save( )

Modified: trunk/server/Slim/Utils/Prefs/OldPrefs.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Prefs/OldPrefs.pm?rev=11776&r1=11775&r2=11776&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Prefs/OldPrefs.pm (original)
+++ trunk/server/Slim/Utils/Prefs/OldPrefs.pm Tue Apr 17 14:51:45 2007
@@ -58,17 +58,17 @@
 
 	my $oldPrefs;
 
-	if (Slim::Utils::OSDetect::OS() eq 'mac') {
+	if ($::prefsfile && -r $::prefsfile) {
+
+		$oldPrefs = $::prefsfile;
+
+	} elsif (Slim::Utils::OSDetect::OS() eq 'mac' && -r catdir($ENV{'HOME'}, 'Library', 'SlimDevices', 'slimserver.pref')) {
 
 		$oldPrefs = catdir($ENV{'HOME'}, 'Library', 'SlimDevices', 'slimserver.pref');
 
-	} elsif (Slim::Utils::OSDetect::OS() eq 'win')  {
+	} elsif (Slim::Utils::OSDetect::OS() eq 'win' && -r catdir($Bin, 'slimserver.pref'))  {
 
 		$oldPrefs = catdir($Bin, 'slimserver.pref');
-
-	} elsif ($::prefsfile && -r $::prefsfile) {
-
-		$oldPrefs = $::prefsfile;
 
 	} elsif (-r '/etc/slimserver.conf') {
 

Modified: trunk/server/scanner.pl
URL: http://svn.slimdevices.com/trunk/server/scanner.pl?rev=11776&r1=11775&r2=11776&view=diff
==============================================================================
--- trunk/server/scanner.pl (original)
+++ trunk/server/scanner.pl Tue Apr 17 14:51:45 2007
@@ -51,6 +51,8 @@
 	our $LogTimestamp = 1;
 
 	my $prefs = preferences('server');
+
+	$prefs->readonly;
 
 	GetOptions(
 		'force'        => \$force,



More information about the checkins mailing list