Skip to content

Commit

Permalink
Check for non-empty target directories
Browse files Browse the repository at this point in the history
This allows the user to re-attempt installation if something fails

Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed Jul 1, 2024
1 parent 630eeff commit ef8b333
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/utils/download.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createWriteStream, existsSync, symlinkSync, unlinkSync } from "fs";
import {
createWriteStream, existsSync, readdirSync, symlinkSync, unlinkSync
} from "fs";
import { mkdir, readFile } from "fs/promises";
import { homedir, tmpdir } from "os";
import { basename, dirname, join } from "path";
Expand Down Expand Up @@ -147,7 +149,10 @@ export async function downloadAndInstallSDK(
const targetDirectory = buildSDKPath(version);

// Check if the SDK is already installed
if (existsSync(targetDirectory)) {
if (
existsSync(targetDirectory)
&& readdirSync(targetDirectory).length !== 0
) {
Logger.log(`SDK ${version} is already installed.`);

return true;
Expand Down Expand Up @@ -204,8 +209,12 @@ async function downloadAndInstallGithubAsset(

redirectURL?: string,
): Promise<boolean> {
// Check if the SDK is already installed
if (redirectURL === undefined && existsSync(targetDirectory)) {
// Check if the asset is already installed
if (
redirectURL === undefined
&& existsSync(targetDirectory)
&& readdirSync(targetDirectory).length !== 0
) {
Logger.log(`${logName} ${version} is already installed.`);

return true;
Expand Down Expand Up @@ -400,7 +409,11 @@ export async function downloadAndInstallToolchain(
const targetDirectory = buildToolchainPath(toolchain.version);

// Check if the SDK is already installed
if (redirectURL === undefined && existsSync(targetDirectory)) {
if (
redirectURL === undefined
&& existsSync(targetDirectory)
&& readdirSync(targetDirectory).length !== 0
) {
Logger.log(`Toolchain ${toolchain.version} is already installed.`);

return true;
Expand Down Expand Up @@ -674,7 +687,11 @@ export async function downloadEmbedPython(
`${HOME_VAR}/.pico-sdk` + `/python/${versionBundle.python.version}`;

// Check if the Embed Python is already installed
if (redirectURL === undefined && existsSync(targetDirectory)) {
if (
redirectURL === undefined
&& existsSync(targetDirectory)
&& readdirSync(targetDirectory).length !== 0
) {
Logger.log(`Embed Python is already installed correctly.`);

return `${settingsTargetDirectory}/python.exe`;
Expand Down

0 comments on commit ef8b333

Please sign in to comment.