refs #1089. Partition assistant. Partition cpt=0
testing/ogcore-api/pipeline/head This commit looks good Details

pull/18/head
Manuel Aranda Rosales 2025-01-09 12:47:15 +01:00
parent 2b8ea31599
commit 46999dfbc7
2 changed files with 21 additions and 6 deletions

View File

@ -6,13 +6,15 @@ use App\Entity\Client;
use App\Entity\OperativeSystem;
use App\Entity\Partition;
use App\Model\PartitionTypes;
use App\Service\Utils\GetPartitionCodeService;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
class CreatePartitionService
{
public function __construct(
protected EntityManagerInterface $entityManager
protected EntityManagerInterface $entityManager,
protected GetPartitionCodeService $partitionCodeService
)
{
}
@ -54,11 +56,15 @@ class CreatePartitionService
$partitionEntity->setSize($cfg['tam']);
if (isset($cfg['cpt']) && $cfg['cpt'] !== '') {
$decimalValue = hexdec($cfg['cpt']);
$partitionType = PartitionTypes::getPartitionType($decimalValue);
if ($cfg['par'] === "0") {
$partitionType = $this->partitionCodeService->__invoke($cfg['cpt']);
} else {
$decimalValue = hexdec($cfg['cpt']);
$partitionType = PartitionTypes::getPartitionType($decimalValue);
}
if ($partitionType) {
$partitionEntity->setPartitionCode($partitionType['name']);
$partitionEntity->setPartitionCode($partitionType['name'] ?? $partitionType);
}
} else {
$partitionEntity->setPartitionCode(PartitionTypes::getPartitionType(0)['name']);

View File

@ -2,7 +2,16 @@
namespace App\Service\Utils;
class GetPartitionCode
class GetPartitionCodeService
{
public function __invoke(string $partitionCode): string
{
return match ($partitionCode) {
"1" => "MSDOS",
"2" => "GPT",
"3" => "LVM",
"4" => "ZPOOL",
default => "UNKNOWN",
};
}
}