Use File facade for files manipulation

This commit is contained in:
DariusIII
2019-01-07 15:30:02 +01:00
parent 041c4e2b33
commit 4ef4b2f6a0
5 changed files with 88 additions and 81 deletions
+5 -4
View File
@@ -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.
@@ -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);
+1
View File
@@ -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
+2 -1
View File
@@ -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);
+71 -67
View File
@@ -1,13 +1,15 @@
<?php
use Illuminate\Support\Facades\File;
if (! isset($argv[1]) || ! isset($argv[2])) {
exit(
'Argument 1 is a input string. ie PRE name.'.PHP_EOL.
'Argument 2 is a expected hash or encoding. ie MD5 string. Passing true on Argument 3 ignores this.'.PHP_EOL.
'Argument 3 (optional) False, exit on first match. True, write all matches to text file in current path.'.PHP_EOL.
'ie: php test_hash_algorithms.php Dog.with.a.Blog.S02E16.Love.Loss.and.a.Beanbag.Toss.HDTV.x264-QCF 11506192c6d92e0c9c795b9997d9396226dbdf62'.PHP_EOL.
'ie: php test_hash_algorithms.php Anchorman.2.The.Legend.Continues.2013.UNRATED.WEBRip.x264-FLS false true'.PHP_EOL
);
'Argument 1 is a input string. ie PRE name.'.PHP_EOL.
'Argument 2 is a expected hash or encoding. ie MD5 string. Passing true on Argument 3 ignores this.'.PHP_EOL.
'Argument 3 (optional) False, exit on first match. True, write all matches to text file in current path.'.PHP_EOL.
'ie: php test_hash_algorithms.php Dog.with.a.Blog.S02E16.Love.Loss.and.a.Beanbag.Toss.HDTV.x264-QCF 11506192c6d92e0c9c795b9997d9396226dbdf62'.PHP_EOL.
'ie: php test_hash_algorithms.php Anchorman.2.The.Legend.Continues.2013.UNRATED.WEBRip.x264-FLS false true'.PHP_EOL
);
}
/**
@@ -43,11 +45,11 @@ class HashAlgorithms
{
$this->_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 = [];