Fix error with async downloading git repos from IPFS gateways

This commit is contained in:
Theo 2023-10-11 03:35:02 -07:00
parent 26a4616c10
commit 369040a409
2 changed files with 4 additions and 4 deletions

@ -5,7 +5,7 @@ if [ "$EUID" -ne 0 ];
exit 1; exit 1;
fi; fi;
this_repo_ipfs_cid="bafybeig4t3ntvqc2skn3qhgr7dhnpzikxxyya6zptonorbcjdsv5emvj7q"; this_repo_ipfs_cid="bafybeiepown476yzjs2zcymrn3t7d4oseuaw6a2rjnkdbu73jrp3evfdxm";
user_home_dir=$(eval echo ~$USER); user_home_dir=$(eval echo ~$USER);
tornado_folder="$user_home_dir/tornado-ipfs"; tornado_folder="$user_home_dir/tornado-ipfs";
script_log_file="/tmp/tornado-ipfs-installation.log"; script_log_file="/tmp/tornado-ipfs-installation.log";

@ -41,11 +41,11 @@ export async function getV1Cids(domains: Domains): Promise<IPFSCids> {
} }
export async function downloadGitRepoFromIpfs(reposFolder: string, repoName: string, repoHash: string, retryAttempt: number = 0) { export async function downloadGitRepoFromIpfs(reposFolder: string, repoName: string, repoHash: string, retryAttempt: number = 0) {
if (retryAttempt > knownIpfsResources.length) return console.error(`Cannot download ${repoName}, all known IPFS gateaways checked.`); if (retryAttempt >= knownIpfsResources.length) return console.error(`Cannot download ${repoName}, all known IPFS gateways checked.`);
try { try {
await git.clone(knownIpfsResources[retryAttempt] + repoHash, path.join(reposFolder, repoName)); await git.clone(knownIpfsResources[retryAttempt] + repoHash, path.join(reposFolder, repoName));
} catch (e) { } catch (e) {
console.error(`Cannot download ${repoName} from ${knownIpfsResources[retryAttempt]}, retry with other gateaway...`); console.error(`Cannot download ${repoName} from ${knownIpfsResources[retryAttempt]}, retry with other gateway...`);
downloadGitRepoFromIpfs(reposFolder, repoName, repoHash, retryAttempt++); await downloadGitRepoFromIpfs(reposFolder, repoName, repoHash, ++retryAttempt);
} }
} }