From d605c096579b00ed9461d15dd532084db76356f8 Mon Sep 17 00:00:00 2001 From: Michael Herger Date: Mon, 3 May 2021 17:09:01 +0200 Subject: [PATCH] More dirsFor fixes --- Slim/Utils/Light.pm | 2 +- Slim/Utils/Misc.pm | 32 +++++++++---------- Slim/Utils/OS/OSX.pm | 2 +- Slim/Utils/OS/Unix.pm | 36 ++++++++++----------- Slim/Utils/OS/Win32.pm | 2 +- Slim/Utils/SQLHelper.pm | 2 +- Slim/Utils/ServiceManager/Win32.pm | 50 +++++++++++++++--------------- Slim/Utils/Update.pm | 12 +++---- 8 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Slim/Utils/Light.pm b/Slim/Utils/Light.pm index 1552e117448..010e2a2964b 100644 --- a/Slim/Utils/Light.pm +++ b/Slim/Utils/Light.pm @@ -179,7 +179,7 @@ sub getPref { $prefFile = catdir(scalar $os->dirsFor('prefs'), 'plugin', $prefFile); } else { - $serverPrefFile ||= catfile( scalar($os->dirsFor('prefs')), 'server.prefs' ); + $serverPrefFile ||= catfile(scalar $os->dirsFor('prefs'), 'server.prefs'); $prefFile = $serverPrefFile; } diff --git a/Slim/Utils/Misc.pm b/Slim/Utils/Misc.pm index 303ca20778c..36bbbf89e83 100644 --- a/Slim/Utils/Misc.pm +++ b/Slim/Utils/Misc.pm @@ -641,17 +641,17 @@ sub getLibraryName { =head2 getTempDir() - Get LMS-private temp dir + Get LMS-private temp dir =cut sub getTempDir { - return $tempdir; + return $tempdir; } =head2 makeTempDir() - make and clean LMS-private temp dir + make and clean LMS-private temp dir =cut @@ -664,32 +664,32 @@ sub makeTempDir { if (-d $tempdir) { rmtree($tempdir, { keep_root => 1 }); return; - } + } mkpath($tempdir); return if -d $tempdir; - - $ospathslog->warn("can't make custom temp dir $tempdir"); - } - + + $ospathslog->warn("can't make custom temp dir $tempdir"); + } + $tempdir = catdir($prefs->get('cachedir'), 'tmp'); - + if (-d $tempdir) { rmtree($tempdir, { keep_root => 1 }); return; - } - + } + mkpath($tempdir); - + if (!-d $tempdir) { $tempdir = tempdir( DIR => $prefs->get('cachedir'), CLEANUP => 1 ); $ospathslog->warn("can't make private temp dir, trying $tempdir"); - } - + } + if (!-d $tempdir) { $tempdir = tempdir( CLEANUP => 1 ); $ospathslog->warn("still can't make private temp dir, using $tempdir"); - } + } } =head2 getAudioDir() @@ -1205,7 +1205,7 @@ sub parseRevision { # The revision file may not exist for svn copies. my $tempBuildInfo = eval { File::Slurp::read_file( - catdir(Slim::Utils::OSDetect::dirsFor('revision'), 'revision.txt') + catdir(scalar Slim::Utils::OSDetect::dirsFor('revision'), 'revision.txt') ) } || "TRUNK\nUNKNOWN"; my ($revision, $builddate) = split (/\n/, $tempBuildInfo); diff --git a/Slim/Utils/OS/OSX.pm b/Slim/Utils/OS/OSX.pm index 573c1a288d7..f1eafcf6d62 100644 --- a/Slim/Utils/OS/OSX.pm +++ b/Slim/Utils/OS/OSX.pm @@ -221,7 +221,7 @@ sub dirsFor { } elsif ($dir eq 'playlists') { - push @dirs, catdir($class->dirsFor('music'), 'Playlists'); + push @dirs, catdir(scalar $class->dirsFor('music'), 'Playlists'); # We might get called from some helper script (update checker) } elsif ($dir eq 'libpath' && $Bin =~ m|Bin/darwin|) { diff --git a/Slim/Utils/OS/Unix.pm b/Slim/Utils/OS/Unix.pm index 3039d5adbea..b1bd8fb6024 100644 --- a/Slim/Utils/OS/Unix.pm +++ b/Slim/Utils/OS/Unix.pm @@ -2,7 +2,7 @@ package Slim::Utils::OS::Unix; # Logitech Media Server Copyright 2001-2020 Logitech. # This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License, +# modify it under the terms of the GNU General Public License, # version 2. use strict; @@ -33,7 +33,7 @@ sub initSearchPath { $class->SUPER::initSearchPath(@_); my @paths = (split(/:/, ($ENV{'PATH'} || '/sbin:/usr/sbin:/bin:/usr/bin')), qw(/usr/bin /usr/local/bin /usr/libexec /sw/bin /usr/sbin /opt/bin)); - + Slim::Utils::Misc::addFindBinPaths(@paths); } @@ -50,7 +50,7 @@ sub dirsFor { my ($class, $dir) = @_; my @dirs = $class->SUPER::dirsFor($dir); - + # some defaults if ($dir =~ /^(?:strings|revision|convert|types|repositories)$/) { @@ -72,9 +72,9 @@ sub dirsFor { } elsif ($dir =~ /^(?:libpath|mysql-language)$/) { } elsif ($dir eq 'prefs' && $::prefsdir) { - + push @dirs, $::prefsdir; - + # SqueezeCenter <= 7.3 prefs } elsif ($dir eq 'scprefs') { @@ -84,23 +84,23 @@ sub dirsFor { @dirs = ( $oldpath ); } elsif ($dir eq 'oldprefs') { - + if ($::prefsfile && -r $::prefsfile) { - + push @dirs, $::prefsfile; - + } elsif (-r '/etc/slimserver.conf') { - + push @dirs, '/etc/slimserver.conf'; - - } elsif (-r catdir($class->dirsFor('prefs'), 'slimserver.pref')) { - - push @dirs, catdir($class->dirsFor('prefs'), 'slimserver.pref'); - + + } elsif (-r catdir(scalar $class->dirsFor('prefs'), 'slimserver.pref')) { + + push @dirs, catdir(scalar $class->dirsFor('prefs'), 'slimserver.pref'); + } elsif (-r catdir($ENV{'HOME'}, 'slimserver.pref')) { - + push @dirs, catdir($ENV{'HOME'}, 'slimserver.pref'); - + } } else { @@ -115,9 +115,9 @@ sub migratePrefsFolder { my ($class, $newdir) = @_; return if -d $newdir && -f catdir($newdir, 'server.prefs'); - + # we only care about SqueezeCenter -> Squeezebox Server for now - my $olddir = $class->dirsFor('scprefs'); + my $olddir = $class->dirsFor('scprefs'); return unless -d $olddir && -r _; diff --git a/Slim/Utils/OS/Win32.pm b/Slim/Utils/OS/Win32.pm index 6497315ac2f..3c1f894686f 100644 --- a/Slim/Utils/OS/Win32.pm +++ b/Slim/Utils/OS/Win32.pm @@ -825,7 +825,7 @@ sub restartServer { elsif ($PerlSvc::VERSION) { - my $restartFlag = catdir( Slim::Utils::Prefs::preferences('server')->get('cachedir') || $class->dirsFor('cache'), 'restart.txt' ); + my $restartFlag = catdir( Slim::Utils::Prefs::preferences('server')->get('cachedir') || scalar $class->dirsFor('cache'), 'restart.txt' ); if (open(RESTART, ">$restartFlag")) { close RESTART; main::stopServer(); diff --git a/Slim/Utils/SQLHelper.pm b/Slim/Utils/SQLHelper.pm index 492128bdcfb..8b1f346054d 100644 --- a/Slim/Utils/SQLHelper.pm +++ b/Slim/Utils/SQLHelper.pm @@ -45,7 +45,7 @@ sub executeSQLFile { my $sqlFile = $file; if (!file_name_is_absolute($file)) { - $sqlFile = catdir(Slim::Utils::OSDetect::dirsFor('SQL'), $driver, $file); + $sqlFile = catdir(scalar Slim::Utils::OSDetect::dirsFor('SQL'), $driver, $file); } main::INFOLOG && logger('database.sql')->info("Executing SQL file $sqlFile"); diff --git a/Slim/Utils/ServiceManager/Win32.pm b/Slim/Utils/ServiceManager/Win32.pm index 33ae2838cdb..3b5a01c9bf7 100644 --- a/Slim/Utils/ServiceManager/Win32.pm +++ b/Slim/Utils/ServiceManager/Win32.pm @@ -2,7 +2,7 @@ package Slim::Utils::ServiceManager::Win32; # Logitech Media Server Copyright 2001-2020 Logitech. # This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License, +# modify it under the terms of the GNU General Public License, # version 2. use base qw(Slim::Utils::ServiceManager); @@ -27,8 +27,8 @@ my $svcHelper; sub init { my $class = shift; $class = $class->SUPER::init(); - $svcHelper = catdir( Win32::GetShortPathName( $os->dirsFor('base') ), 'server', 'squeezesvc.exe' ); - + $svcHelper = catdir( Win32::GetShortPathName( scalar $os->dirsFor('base') ), 'server', 'squeezesvc.exe' ); + return $class; } @@ -51,13 +51,13 @@ sub getStartupType { sub canSetStartupType { - # on Vista+ we can elevate privileges + # on Vista+ we can elevate privileges if ($os->get('isVista')) { return 1; } - + # on other Windows versions we have to be member of the administrators group to be able to manage the service - # only return true if SC isn't configured to be run as a background service, OR if the user is an admin + # only return true if SC isn't configured to be run as a background service, OR if the user is an admin else { my $isService = (getStartupType() == SC_STARTUP_TYPE_SERVICE); @@ -67,10 +67,10 @@ sub canSetStartupType { sub getStartupOptions { my $class = shift; - + if (!$os->get('isVista') && !Win32::IsAdminUser()) { return ('CONTROLPANEL_NEED_ADMINISTRATOR', 'RUN_NEVER', 'RUN_AT_LOGIN'); - } + } return $class->SUPER::getStartupOptions(); } @@ -78,23 +78,23 @@ sub getStartupOptions { sub setStartupType { my ($class, $type, $username, $password) = @_; $username = '' unless defined $username; - + $Registry->{SB_USER_REGISTRY_KEY . '/StartAtLogin'} = ($type == SC_STARTUP_TYPE_LOGIN || 0); # enable service mode if ($type == SC_STARTUP_TYPE_SERVICE) { my @args; - + push @args, "--username=$username" if $username; push @args, "--password=$password" if $password; push @args, '--install'; - + system($svcHelper, @args); } else { system($svcHelper, "--remove"); } - + return 1; } @@ -103,16 +103,16 @@ sub initStartupType { # preset atLogin if it isn't defined yet my $atLogin = $Registry->{SB_USER_REGISTRY_KEY . '/StartAtLogin'}; - + if ($atLogin !~ /[01]/) { - + # make sure our Key does exist before we can write to it if (! (my $regKey = $Registry->{SB_USER_REGISTRY_KEY . ''})) { $Registry->{'CUser/Software/Logitech/'} = { 'Squeezebox/' => {} }; } - + # migrate startup setting if (defined $Registry->{SC_USER_REGISTRY_KEY . '/StartAtLogin'}) { $Registry->{SB_USER_REGISTRY_KEY . '/StartAtLogin'} = $Registry->{SC_USER_REGISTRY_KEY . '/StartAtLogin'}; @@ -129,7 +129,7 @@ sub canStart { sub start { my ($class, $params) = @_; - + if (!$params && $class->getStartupType() == SC_STARTUP_TYPE_SERVICE) { `$svcHelper --start`; @@ -137,15 +137,15 @@ sub start { else { - my $appExe = Win32::GetShortPathName( catdir( $os->dirsFor('base'), 'server', 'SqueezeSvr.exe' ) ); - + my $appExe = Win32::GetShortPathName( catdir( scalar $os->dirsFor('base'), 'server', 'SqueezeSvr.exe' ) ); + if ($params) { $params = "$appExe $params"; } else { $params = ''; } - + # start as background job my $processObj; Win32::Process::Create( @@ -165,7 +165,7 @@ sub start { sub checkServiceState { my $class = shift; - + if ($class->getStartupType() == SC_STARTUP_TYPE_SERVICE) { my %status = (); @@ -189,7 +189,7 @@ sub checkServiceState { # it could happen SC has been started as an app, even though # it's configured to be running as a service if (getProcessID() != -1) { - + $class->{status} = SC_STATE_RUNNING; } } @@ -205,12 +205,12 @@ sub checkServiceState { $class->{status} = SC_STATE_RUNNING; } - + else { - + $class->{status} = SC_STATE_STOPPED; } - + } if ($class->{status} == SC_STATE_RUNNING) { @@ -225,7 +225,7 @@ sub checkServiceState { $class->{checkHTTP} = 0; } } - + return $class->{status}; } diff --git a/Slim/Utils/Update.pm b/Slim/Utils/Update.pm index fc9f0bf2852..f5a59e46314 100644 --- a/Slim/Utils/Update.pm +++ b/Slim/Utils/Update.pm @@ -32,7 +32,7 @@ sub checkVersion { # clean up old download location Slim::Utils::Misc::deleteFiles($prefs->get('cachedir'), qr/^(?:Squeezebox|SqueezeCenter|LogitechMediaServer).*\.(pkg|dmg|exe)(\.tmp)?$/i); - Slim::Utils::Timers::killTimers(0, \&checkVersion); + Slim::Utils::Timers::killTimers(0, \&checkVersion); # don't check for updates when running from the source if ($os->runningFromSource) { @@ -80,9 +80,9 @@ sub checkVersion { my $url = main::NOMYSB ? (Slim::Networking::Repositories->getUrlForRepository('servers') . "$::VERSION/servers.xml") : (Slim::Networking::SqueezeNetwork->url('') . '/update/'); $url .= sprintf( - "?version=%s&revision=%s&lang=%s&geturl=%s&os=%s&uuid=%s&pcount=%d", - $::VERSION, - $::REVISION, + "?version=%s&revision=%s&lang=%s&geturl=%s&os=%s&uuid=%s&pcount=%d", + $::VERSION, + $::REVISION, Slim::Utils::Strings::getLanguage(), $os->canAutoUpdate() && $prefs->get('autoDownloadUpdate') ? '1' : '0', $os->canAutoUpdate() ? $os->installerOS() : '', @@ -321,7 +321,7 @@ sub setUpdateInstaller { } sub getVersionFile { - $versionFile ||= catdir( scalar($os->dirsFor('updates')), 'server.version' ); + $versionFile ||= catdir( scalar $os->dirsFor('updates'), 'server.version' ); return $versionFile; } @@ -336,7 +336,7 @@ sub getUpdateInstaller { open(UPDATEFLAG, $versionFile) || do { main::DEBUGLOG && $log->is_debug && $log->debug("No '$versionFile' available."); - return ''; + return ''; }; my $updateInstaller = '';