Skip to content

Commit

Permalink
More dirsFor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mherger committed May 3, 2021
1 parent 93746f1 commit d605c09
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Slim/Utils/Light.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
32 changes: 16 additions & 16 deletions Slim/Utils/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Slim/Utils/OS/OSX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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|) {
Expand Down
36 changes: 18 additions & 18 deletions Slim/Utils/OS/Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -50,7 +50,7 @@ sub dirsFor {
my ($class, $dir) = @_;

my @dirs = $class->SUPER::dirsFor($dir);

# some defaults
if ($dir =~ /^(?:strings|revision|convert|types|repositories)$/) {

Expand All @@ -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') {

Expand All @@ -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 {
Expand All @@ -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 _;

Expand Down
2 changes: 1 addition & 1 deletion Slim/Utils/OS/Win32.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Slim/Utils/SQLHelper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
50 changes: 25 additions & 25 deletions Slim/Utils/ServiceManager/Win32.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -67,34 +67,34 @@ 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();
}

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;
}

Expand All @@ -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'};
Expand All @@ -129,23 +129,23 @@ sub canStart {

sub start {
my ($class, $params) = @_;

if (!$params && $class->getStartupType() == SC_STARTUP_TYPE_SERVICE) {

`$svcHelper --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(
Expand All @@ -165,7 +165,7 @@ sub start {

sub checkServiceState {
my $class = shift;

if ($class->getStartupType() == SC_STARTUP_TYPE_SERVICE) {

my %status = ();
Expand All @@ -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;
}
}
Expand All @@ -205,12 +205,12 @@ sub checkServiceState {

$class->{status} = SC_STATE_RUNNING;
}

else {

$class->{status} = SC_STATE_STOPPED;
}

}

if ($class->{status} == SC_STATE_RUNNING) {
Expand All @@ -225,7 +225,7 @@ sub checkServiceState {
$class->{checkHTTP} = 0;
}
}

return $class->{status};
}

Expand Down
Loading

0 comments on commit d605c09

Please sign in to comment.