From 4ef4b2f6a0df9e552c2cb352f01d2378e607d3a9 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 7 Jan 2019 15:30:02 +0100 Subject: [PATCH] Use File facade for files manipulation --- Blacklight/Nfo.php | 9 +- .../processing/post/ProcessAdditional.php | 18 +-- Changelog | 1 + app/Console/Commands/InstallNntmux.php | 3 +- misc/testing/Dev/test_hash_algorithms.php | 138 +++++++++--------- 5 files changed, 88 insertions(+), 81 deletions(-) diff --git a/Blacklight/Nfo.php b/Blacklight/Nfo.php index eaf2c0c42..ff4aeade9 100755 --- a/Blacklight/Nfo.php +++ b/Blacklight/Nfo.php @@ -11,6 +11,7 @@ use Blacklight\utility\Utility; use dariusiii\rarinfo\Par2Info; use Illuminate\Support\Facades\DB; use Blacklight\processing\PostProcess; +use Illuminate\Support\Facades\File; /** * Class Nfo. @@ -141,7 +142,7 @@ class Nfo )) { // File/GetId3 work with files, so save to disk. $tmpPath = $this->tmpPath.$guid.'.nfo'; - file_put_contents($tmpPath, $possibleNFO); + File::put($tmpPath, $possibleNFO); // Linux boxes have 'file' (so should Macs), Windows *can* have it too: see GNUWIN.txt in docs. $result = Utility::fileInfo($tmpPath); @@ -149,7 +150,7 @@ class Nfo // Check if it's text. if (preg_match('/(ASCII|ISO-8859|UTF-(8|16|32).*?)\s*text/', $result)) { - @unlink($tmpPath); + @File::delete($tmpPath); return true; @@ -157,7 +158,7 @@ class Nfo } if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || preg_match('/[\x00-\x08\x12-\x1F\x0B\x0E\x0F]/', $possibleNFO)) { - @unlink($tmpPath); + @File::delete($tmpPath); return false; } @@ -165,7 +166,7 @@ class Nfo // If above checks couldn't make a categorical identification, Use GetId3 to check if it's an image/video/rar/zip etc.. $check = (new \getID3())->analyze($tmpPath); - @unlink($tmpPath); + @File::delete($tmpPath); if (isset($check['error'])) { // Check if it's a par2. diff --git a/Blacklight/processing/post/ProcessAdditional.php b/Blacklight/processing/post/ProcessAdditional.php index 2ea580f09..47e891ff0 100755 --- a/Blacklight/processing/post/ProcessAdditional.php +++ b/Blacklight/processing/post/ProcessAdditional.php @@ -1080,13 +1080,13 @@ class ProcessAdditional if ($this->_extractUsingRarInfo === false && $this->_unrarPath !== false) { $fileName = $this->tmpPath.uniqid('', true).'.rar'; - file_put_contents($fileName, $compressedData); + File::put($fileName, $compressedData); runCmd( $this->_killString.$this->_unrarPath. '" e -ai -ep -c- -id -inul -kb -or -p- -r -y "'. $fileName.'" "'.$this->tmpPath.'unrar/"' ); - unlink($fileName); + File::delete($fileName); } break; case ArchiveInfo::TYPE_ZIP: @@ -1096,12 +1096,12 @@ class ProcessAdditional if ($this->_extractUsingRarInfo === false && $this->_7zipPath !== false) { $fileName = $this->tmpPath.uniqid('', true).'.zip'; - file_put_contents($fileName, $compressedData); + File::put($fileName, $compressedData); runCmd( $this->_killString.$this->_7zipPath.'" x "'. $fileName.'" -bd -y -o"'.$this->tmpPath.'unzip/"' ); - unlink($fileName); + File::delete($fileName); } break; default: @@ -1791,14 +1791,14 @@ class ProcessAdditional if (File::isFile($this->tmpPath.$audioFileName)) { // Try to move the temp audio file. - $renamed = rename($this->tmpPath.$audioFileName, $this->_audioSavePath.$audioFileName); + $renamed = File::move($this->tmpPath.$audioFileName, $this->_audioSavePath.$audioFileName); if (! $renamed) { // Try to copy it if it fails. - $copied = copy($this->tmpPath.$audioFileName, $this->_audioSavePath.$audioFileName); + $copied = File::copy($this->tmpPath.$audioFileName, $this->_audioSavePath.$audioFileName); // Delete the old file. - unlink($this->tmpPath.$audioFileName); + File::delete($this->tmpPath.$audioFileName); // If it didn't copy continue. if (! $copied) { @@ -2023,11 +2023,11 @@ class ProcessAdditional $newFile = ($this->_releaseImage->vidSavePath.$this->_release->guid.'.ogv'); // Try to move the file to the new path. - $renamed = @rename($fileName, $newFile); + $renamed = @File::move($fileName, $newFile); // If we couldn't rename it, try to copy it. if (! $renamed) { - $copied = @copy($fileName, $newFile); + $copied = @File::copy($fileName, $newFile); // Delete the old file. File::delete($fileName); diff --git a/Changelog b/Changelog index 5b5849ee3..cba9591cb 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-01-07 DariusIII + * Chg: Use File facade for files manipulation * Chg: Update opis/closure to version 3.1.3 2019-01-06 DariusIII * Chg: Remove debug code from predb_import_daily_batch.php diff --git a/app/Console/Commands/InstallNntmux.php b/app/Console/Commands/InstallNntmux.php index a5d8c2926..81fea2d1c 100644 --- a/app/Console/Commands/InstallNntmux.php +++ b/app/Console/Commands/InstallNntmux.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Models\User; use App\Models\Settings; use Illuminate\Console\Command; +use Illuminate\Support\Facades\File; use Symfony\Component\Process\Process; class InstallNntmux extends Command @@ -105,7 +106,7 @@ class InstallNntmux extends Command } if (! $error && $this->addAdminUser()) { - @file_put_contents(base_path().'/_install/install.lock', 'application install locked on '.now()); + File::put(base_path().'/_install/install.lock', 'application install locked on '.now()); $this->info('Generating application key'); $process = new Process('php artisan key:generate --force'); $process->setTimeout(600); diff --git a/misc/testing/Dev/test_hash_algorithms.php b/misc/testing/Dev/test_hash_algorithms.php index 54a653fad..14ee8042f 100644 --- a/misc/testing/Dev/test_hash_algorithms.php +++ b/misc/testing/Dev/test_hash_algorithms.php @@ -1,13 +1,15 @@ _inputString = $inputString; $this->_expectedString = [ - $expectedString, - strtolower($expectedString), - strtoupper($expectedString), - strrev($expectedString), - ]; + $expectedString, + strtolower($expectedString), + strtoupper($expectedString), + strrev($expectedString), + ]; $this->_writeToFile = $writeToFile; $this->_testStrings(); } @@ -60,7 +62,7 @@ class HashAlgorithms protected function _testStrings() { if ($this->_writeToFile) { - file_put_contents('hash_matches.txt', ''); + File::put('hash_matches.txt', ''); } $firstArray = $this->_hashesToArray($this->_inputString); @@ -68,20 +70,20 @@ class HashAlgorithms $secondArray = []; foreach ($firstArray as $key => $value) { if (! $this->_writeToFile) { - if (in_array($value, $this->_expectedString)) { + if (\in_array($value, $this->_expectedString, false)) { exit( - '['. - $this->_inputString. - ']=>['. - $key. - ']=>'. - $value. - ']'. - PHP_EOL - ); + '['. + $this->_inputString. + ']=>['. + $key. + ']=>'. + $value. + ']'. + PHP_EOL + ); } } else { - file_put_contents('hash_matches.txt', $key."\t\t".$value.PHP_EOL, FILE_APPEND); + File::put('hash_matches.txt', $key."\t\t".$value.PHP_EOL, FILE_APPEND); } $secondArray[$key] = $this->_hashesToArray($value); } @@ -90,24 +92,24 @@ class HashAlgorithms foreach ($secondArray as $key => $value) { foreach ($value as $key2 => $value2) { if (! $this->_writeToFile) { - if (in_array($value2, $this->_expectedString)) { + if (\in_array($value2, $this->_expectedString, false)) { exit( - '['. - $this->_inputString. - ']=>['. - $key. - ']=>['. - $firstArray[$key]. - ']=>['. - $key2. - ']=>['. - $value2. - ']'. - PHP_EOL - ); + '['. + $this->_inputString. + ']=>['. + $key. + ']=>['. + $firstArray[$key]. + ']=>['. + $key2. + ']=>['. + $value2. + ']'. + PHP_EOL + ); } } else { - file_put_contents('hash_matches.txt', $key.' => '.$key2."\t\t".$value2.PHP_EOL, FILE_APPEND); + File::put('hash_matches.txt', $key.' => '.$key2."\t\t".$value2.PHP_EOL, FILE_APPEND); } $thirdArray[$key][$key2] = $this->_hashesToArray($value2); } @@ -119,28 +121,30 @@ class HashAlgorithms if (! $this->_writeToFile) { if (in_array($value3, $this->_expectedString)) { exit( - '['. - $this->_inputString. - ']=>['. - $key. - ']=>['. - $firstArray[$key]. - ']=>['. - $key2. - ']=>['. - $value2. - ']=>['. - $key3. - ']=>['. - $value3. - ']'. - PHP_EOL - ); + '['. + $this->_inputString. + ']=>['. + $key. + ']=>['. + $firstArray[$key]. + ']=>['. + $key2. + ']=>['. + $value2. + ']=>['. + $key3. + ']=>['. + $value3. + ']'. + PHP_EOL + ); } } else { - file_put_contents('hash_matches.txt', - $key.' => '.$key2.' => '.$key3."\t\t".$value3.PHP_EOL, FILE_APPEND - ); + File::put( + 'hash_matches.txt', + $key.' => '.$key2.' => '.$key3."\t\t".$value3.PHP_EOL, + FILE_APPEND + ); } } } @@ -157,15 +161,15 @@ class HashAlgorithms protected function _hashesToArray($string) { $strings = [ - 'input' => $string, - 'lower' => strtolower($string), - 'lower_reverse' => strtolower(strrev($string)), - 'upper_reverse' => strtoupper(strrev($string)), - 'upper' => strtoupper($string), - 'reverse' => strrev($string), - 'reverse_upper' => strrev(strtoupper($string)), - 'reverse_lower' => strrev(strtolower($string)), - ]; + 'input' => $string, + 'lower' => strtolower($string), + 'lower_reverse' => strtolower(strrev($string)), + 'upper_reverse' => strtoupper(strrev($string)), + 'upper' => strtoupper($string), + 'reverse' => strrev($string), + 'reverse_upper' => strrev(strtoupper($string)), + 'reverse_lower' => strrev(strtolower($string)), + ]; $hashTypes = ['md5', 'md4', 'sha1', 'sha256', 'sha512']; $tmpArray = [];