Better catch TIC file exceptions, enable moving TIC files if fido.packet_keep is defined

This commit is contained in:
Deon George 2023-10-04 22:22:01 +11:00
parent ce7a96ca2a
commit b854cf9fe0
4 changed files with 39 additions and 11 deletions

View File

@ -292,11 +292,11 @@ class Tic extends FTNBase
// Validate Size
if ($this->fo->size !== ($y=$fs->size($this->fo->recvd_rel_name)))
throw new \Exception(sprintf('TIC file size [%d] doesnt match file [%s] (%d)',$this->fo->size,$this->fo->fullname,$y));
throw new \Exception(sprintf('TIC file size [%d] doesnt match file [%s] (%d)',$this->fo->size,$this->fo->recvd_rel_name,$y));
// Validate CRC
if (sprintf('%08x',$this->fo->crc) !== ($y=$fs->checksum($this->fo->recvd_rel_name,['checksum_algo'=>'crc32b'])))
throw new \Exception(sprintf('TIC file CRC [%08x] doesnt match file [%s] (%s)',$this->fo->crc,$this->fo->fullname,$y));
throw new \Exception(sprintf('TIC file CRC [%08x] doesnt match file [%s] (%s)',$this->fo->crc,$this->fo->recvd_rel_name,$y));
// Validate Password
if ($pw !== ($y=$this->from->session('ticpass')))

View File

@ -142,7 +142,7 @@ class Receive extends Base
Log::info(sprintf('%s:- Processing TIC file [%s]',self::LOGKEY,$this->receiving->nameas));
// Queue the tic to be processed later, in case the referenced file hasnt been received yet
TicProcess::dispatch($this->receiving->rel_name);
TicProcess::dispatch($this->receiving->pref_name)->delay(60);
break;

View File

@ -58,6 +58,7 @@ class PacketProcess implements ShouldQueue
$fs = Storage::disk(config('fido.local_disk'));
// @todo Catch files that we cannot process, eg: ARJ bundles.
try {
$f = new File($this->file->full_name);
$processed = FALSE;
@ -131,8 +132,7 @@ class PacketProcess implements ShouldQueue
} else {
// If we want to keep the packet, we could do that logic here
if (config('fido.packet_keep')) {
$now = Carbon::now()->format('Ymd');
$dir = sprintf('%s/%s',config('fido.dir'),$now);
$dir = sprintf('%s/%s',config('fido.dir'),Carbon::now()->format('Ymd'));
Log::debug(sprintf('%s:- Moving processed packet [%s] to [%s]',self::LOGKEY,$this->file->rel_name,$dir));
try {

View File

@ -2,8 +2,8 @@
namespace App\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -11,6 +11,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToMoveFile;
use App\Classes\FTN\Tic;
use App\Models\Domain;
@ -28,7 +29,7 @@ class TicProcess implements ShouldQueue
/**
* Create a new job instance.
*
* @param string $file Relative to Storage::disk('local'), ie: storage/app
* @param string $file Received name, stored in Storage::disk('local'), ie: storage/app
* @param string|null $domain
*/
public function __construct(private string $file,private ?string $domain=NULL)
@ -53,19 +54,46 @@ class TicProcess implements ShouldQueue
* Execute the job.
*
* @return void
* @throws FileNotFoundException
*/
public function handle()
{
$fs = Storage::disk(config('fido.local_disk'));
$rel_name = sprintf('%s/%s',config('fido.dir'),$this->file);
$to = new Tic;
$to->load($this->file);
try {
$to->load($fs->path($rel_name));
} catch (\Exception $e) {
Log::error(sprintf('%s:! Error loading TIC file [%s]',self::LOGKEY,$rel_name));
return;
}
Log::info(sprintf('%s:= Processed [%s] storing [%s] as id [%d]',self::LOGKEY,$this->file,$to->fo->name,$to->fo->id));
if (! $fs->delete($this->file))
Log::alert(sprintf('%s:! Failed to delete [%s]',self::LOGKEY,$this->file));
if (config('fido.packet_keep')) {
$dir = sprintf('%s/%s',config('fido.dir'),Carbon::now()->format('Ymd'));
Log::debug(sprintf('%s:- Moving processed TIC [%s] to [%s]',self::LOGKEY,$rel_name,$dir));
try {
if ($fs->makeDirectory($dir)) {
$fs->move($rel_name,$x=sprintf('%s/%s/%s',config('fido.dir'),$dir,$this->file));
Log::info(sprintf('%s:- Moved processed TIC [%s] to [%s]',self::LOGKEY,$rel_name,$x));
} else
Log::error(sprintf('%s:! Unable to create dir [%s]',self::LOGKEY,$dir));
} catch (UnableToMoveFile $e) {
Log::error(sprintf('%s:! Unable to move TIC [%s] to [%s] (%s)',self::LOGKEY,$rel_name,$dir,$e->getMessage()));
} catch (\Exception $e) {
Log::error(sprintf('%s:! Failed moving TIC [%s] to [%s] (%s)',self::LOGKEY,$rel_name,$dir,$e->getMessage()));
}
} else {
if (! $fs->delete($rel_name))
Log::alert(sprintf('%s:! Failed to delete [%s]',self::LOGKEY,$rel_name));
}
if ($to->isNodelist())
NodelistImport::dispatch($to->fo,$this->domain);