Skip to content

Commit

Permalink
add SourcePatcher::patchFile
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywhalecc committed Oct 14, 2023
1 parent 56caef7 commit 1deda4e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/SPC/store/SourcePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ public static function patchMicro(?array $list = null, bool $reverse = false): b
return true;
}

/**
* Use existing patch file for patching
*
* @param string $patch_name Patch file name in src/globals/patch/
* @param string $cwd Working directory for patch command
* @param bool $reverse Reverse patches (default: False)
* @throws RuntimeException
*/
public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool
{
if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) {
return false;
}

$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);

f_passthru(
'cd ' . $cwd . ' && ' .
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patch_str . ' | patch -p1 ' . ($reverse ? '-R' : '')
);
return true;
}

/**
* @throws FileSystemException
*/
Expand Down

0 comments on commit 1deda4e

Please sign in to comment.