13,005
回編集
(→圧縮) |
(→解凍) |
||
375行目: | 375行目: | ||
{ | { | ||
try { | try { | ||
// ファイルの検証 | |||
validateFile($sourceFile); | |||
if (!file_exists($sourceFile)) { | if (!file_exists($sourceFile)) { | ||
throw new RuntimeException('指定されたZIPファイルが存在しません'); | throw new RuntimeException('指定されたZIPファイルが存在しません'); | ||
401行目: | 404行目: | ||
catch (\Exception $e) { | catch (\Exception $e) { | ||
throw new RuntimeException("ZIP解凍処理中にエラーが発生しました: {$e->getMessage()}"); | throw new RuntimeException("ZIP解凍処理中にエラーが発生しました: {$e->getMessage()}"); | ||
} | |||
} | |||
/** | |||
* ファイルの存在確認と権限チェックを行うプライベートメソッド | |||
* | |||
* @param string $filePath チェック対象のファイルパス | |||
* @throws RuntimeException チェック失敗時 | |||
*/ | |||
function validateFile(string $filePath): void | |||
{ | |||
if (!file_exists($filePath)) { | |||
throw new RuntimeException("ファイルが存在しません: {$filePath}"); | |||
} | |||
if (!is_readable($filePath)) { | |||
throw new RuntimeException("ファイルの読み取り権限がありません: {$filePath}"); | |||
} | |||
if (!is_file($filePath)) { | |||
throw new RuntimeException("指定されたパスがファイルではありません: {$filePath}"); | |||
} | } | ||
} | } | ||
438行目: | 462行目: | ||
{ | { | ||
try { | try { | ||
// ファイルの検証 | |||
validateFile($sourceFile); | |||
if (!file_exists($sourceFile)) { | if (!file_exists($sourceFile)) { | ||
throw new RuntimeException('指定されたtar.gzファイルが存在しません'); | throw new RuntimeException('指定されたtar.gzファイルが存在しません'); | ||
485行目: | 512行目: | ||
catch (\Exception $e) { | catch (\Exception $e) { | ||
throw new RuntimeException("tar.gz解凍処理中にエラーが発生しました: {$e->getMessage()}"); | throw new RuntimeException("tar.gz解凍処理中にエラーが発生しました: {$e->getMessage()}"); | ||
} | |||
} | |||
/** | |||
* ファイルの存在確認と権限チェックを行うプライベートメソッド | |||
* | |||
* @param string $filePath チェック対象のファイルパス | |||
* @throws RuntimeException チェック失敗時 | |||
*/ | |||
function validateFile(string $filePath): void | |||
{ | |||
if (!file_exists($filePath)) { | |||
throw new RuntimeException("ファイルが存在しません: {$filePath}"); | |||
} | |||
if (!is_readable($filePath)) { | |||
throw new RuntimeException("ファイルの読み取り権限がありません: {$filePath}"); | |||
} | |||
if (!is_file($filePath)) { | |||
throw new RuntimeException("指定されたパスがファイルではありません: {$filePath}"); | |||
} | } | ||
} | } | ||
522行目: | 570行目: | ||
{ | { | ||
try { | try { | ||
// ファイルの検証 | |||
validateFile($sourceFile); | |||
if (!extension_loaded('xz')) { | if (!extension_loaded('xz')) { | ||
throw new RuntimeException('XZ拡張機能がインストールされていません'); | throw new RuntimeException('XZ拡張機能がインストールされていません'); | ||
573行目: | 624行目: | ||
catch (\Exception $e) { | catch (\Exception $e) { | ||
throw new RuntimeException("tar.xz解凍処理中にエラーが発生しました: {$e->getMessage()}"); | throw new RuntimeException("tar.xz解凍処理中にエラーが発生しました: {$e->getMessage()}"); | ||
} | |||
} | |||
/** | |||
* ファイルの存在確認と権限チェックを行うプライベートメソッド | |||
* | |||
* @param string $filePath チェック対象のファイルパス | |||
* @throws RuntimeException チェック失敗時 | |||
*/ | |||
function validateFile(string $filePath): void | |||
{ | |||
if (!file_exists($filePath)) { | |||
throw new RuntimeException("ファイルが存在しません: {$filePath}"); | |||
} | |||
if (!is_readable($filePath)) { | |||
throw new RuntimeException("ファイルの読み取り権限がありません: {$filePath}"); | |||
} | |||
if (!is_file($filePath)) { | |||
throw new RuntimeException("指定されたパスがファイルではありません: {$filePath}"); | |||
} | } | ||
} | } | ||
606行目: | 678行目: | ||
try { | try { | ||
// ファイルの検証 | |||
validateFile($sourceFile); | |||
switch ($type) { | switch ($type) { | ||
case 'zip': | case 'zip': | ||
628行目: | 703行目: | ||
yield "解凍処理中にエラーが発生しました: {$e->getMessage()}"; | yield "解凍処理中にエラーが発生しました: {$e->getMessage()}"; | ||
throw $e; | throw $e; | ||
} | |||
} | |||
/** | |||
* ファイルの存在確認と権限チェックを行うプライベートメソッド | |||
* | |||
* @param string $filePath チェック対象のファイルパス | |||
* @throws RuntimeException チェック失敗時 | |||
*/ | |||
function validateFile(string $filePath): void | |||
{ | |||
if (!file_exists($filePath)) { | |||
throw new RuntimeException("ファイルが存在しません: {$filePath}"); | |||
} | |||
if (!is_readable($filePath)) { | |||
throw new RuntimeException("ファイルの読み取り権限がありません: {$filePath}"); | |||
} | |||
if (!is_file($filePath)) { | |||
throw new RuntimeException("指定されたパスがファイルではありません: {$filePath}"); | |||
} | } | ||
} | } |