@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use PhutilGitHubReleaseDownloader

Summary:
Similar to how D26785 does this for PhutilPHPParserLibrary.

Requires D26785 in rARC.

Test Plan:
* Remove your local installation of Peast and run support/peast/build-peast.php
* Run again to observe existing file is reused

Reviewers: avivey, O1 Blessed Committers

Reviewed By: avivey, O1 Blessed Committers

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D26786

+17 -38
+17 -38
src/infrastructure/javelin/JavelinPeastLibrary.php
··· 24 24 25 25 private static $version; 26 26 27 - private static function downloadPeast(string $path, string $extension) { 28 - $path .= '/peast-'.self::EXPECTED_VERSION.$extension; 29 - 30 - // Skip downloading if the file already exists and matches the hash. 31 - if ( 32 - Filesystem::pathExists($path) && 33 - in_array(md5_file($path), self::$hashes, true)) { 34 - 35 - return $path; 36 - } 37 - 38 - // HTTPSFuture::setDownloadPath refuses to overwrite. 39 - Filesystem::remove($path); 40 - 41 - $future = new HTTPSFuture( 42 - self::REPO.'/archive/refs/tags/v'.self::EXPECTED_VERSION.$extension); 43 - $future 44 - ->setDownloadPath($path) 45 - ->resolvex(); 46 - 47 - $actual_md5 = md5_file($path); 48 - 49 - if (!in_array($actual_md5, self::$hashes, true)) { 50 - $expected = implode(', ', self::$hashes); 51 - 52 - throw new Exception( 53 - "Peast hash does not match: expected any of {$expected}". 54 - ", got {$actual_md5}."); 55 - } 56 - 57 - return $path; 58 - } 59 - 60 27 public static function build() { 61 28 $root = phutil_get_library_root('phorge'); 62 29 $path = Filesystem::resolvePath($root.'/../support/peast'); ··· 64 31 $version = self::EXPECTED_VERSION; 65 32 66 33 if (extension_loaded('zip')) { 67 - $download_path = self::downloadPeast($path, '.zip'); 34 + $target_path = $path.'/peast-'.$version.'.zip'; 35 + 36 + id(new PhutilGitHubReleaseDownloader(self::REPO, $target_path)) 37 + ->setDownloadFormat('zip') 38 + ->setVersion($version) 39 + ->validateDownload(self::$hashes) 40 + ->download(); 68 41 69 42 $zip = new ZipArchive(); 70 - $result = $zip->open($download_path); 43 + $result = $zip->open($target_path); 71 44 if (!$result) { 72 45 throw new Exception( 73 46 pht( 74 47 'Opening %s failed! %s.', 75 - $download_path, 48 + $target_path, 76 49 $result === false ? 'Unknown Error' : (string)$result)); 77 50 } 78 51 ··· 90 63 extension_loaded('phar') && 91 64 extension_loaded('zlib')) { 92 65 93 - $download_path = self::downloadPeast($path, '.tar.gz'); 66 + $target_path = $path.'/peast-'.$version.'.tar.gz'; 94 67 95 - id(new PharData($download_path))->extractTo($target, null, true); 68 + id(new PhutilGitHubReleaseDownloader(self::REPO, $target_path)) 69 + ->setDownloadFormat('tar.gz') 70 + ->setVersion($version) 71 + ->validateDownload(self::$hashes) 72 + ->download(); 73 + 74 + id(new PharData($target_path))->extractTo($target, null, true); 96 75 97 76 // Renames fail if the target directory exists. 98 77 Filesystem::remove("{$target}/Peast");