Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Exceptions/CloseFeedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelFeed\Exceptions;

use RuntimeException;
use Throwable;

// @codeCoverageIgnoreStart
class CloseFeedException extends RuntimeException
{
public function __construct(string $path, Throwable $e)
{
parent::__construct($e->getMessage() . ": [$path]", previous: $e);
}
}
// @codeCoverageIgnoreEnd
2 changes: 1 addition & 1 deletion src/Exceptions/OpenFeedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OpenFeedException extends RuntimeException
{
public function __construct(string $path, Throwable $e)
{
parent::__construct("Unable to open file for writing: [$path]", previous: $e);
parent::__construct($e->getMessage() . ": [$path]", previous: $e);
}
}
// @codeCoverageIgnoreEnd
27 changes: 16 additions & 11 deletions src/Services/FilesystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DragonCode\LaravelFeed\Services;

use DragonCode\LaravelFeed\Exceptions\CloseFeedException;
use DragonCode\LaravelFeed\Exceptions\OpenFeedException;
use DragonCode\LaravelFeed\Exceptions\ResourceMetaException;
use DragonCode\LaravelFeed\Exceptions\WriteFeedException;
Expand Down Expand Up @@ -73,22 +74,26 @@ public function append($resource, string $content, string $path): void // @pest-
*/
public function release($resource, string $path): void // @pest-ignore-type
{
$temp = $this->getMetaPath($resource);
try {
$temp = $this->getMetaPath($resource);

$this->unlock($resource);
$this->close($resource);
$this->unlock($resource);
$this->close($resource);

if ($this->file->exists($path)) {
$this->file->delete($path);
}
if ($this->file->exists($path)) {
$this->file->delete($path);
}

$this->file->ensureDirectoryExists(
dirname($path)
);
$this->file->ensureDirectoryExists(
dirname($path)
);

$this->file->move($temp, $path);
$this->file->move($temp, $path);

$this->cleanTemporaryDirectory($temp);
$this->cleanTemporaryDirectory($temp);
} catch (Throwable $e) {
throw new CloseFeedException($path, $e);
}
}

/**
Expand Down