Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite existing installations when linking to SDK #519

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cp, mkdir, readdir, readFile, symlink } from "node:fs/promises"
import { cp, mkdir, readdir, readFile, rm, symlink } from "node:fs/promises"
import * as os from "node:os"
import * as path from "node:path"
import { env } from "node:process"
Expand Down Expand Up @@ -78,33 +78,45 @@ export async function getNdk(version: string, options: Options) {
core.warning("Failed to detect full version")
}

if (options.linkToSdk && fullVersion && "ANDROID_HOME" in env) {
await linkToSdk(installPath, fullVersion, env.ANDROID_HOME!)
if (options.linkToSdk) {
await linkToSdk(installPath, fullVersion, env.ANDROID_HOME)
}

return { path: installPath, fullVersion }
}

async function linkToSdk(
installPath: string,
fullVersion: string,
androidHome: string,
fullVersion: string | undefined,
androidHome: string | undefined,
) {
if (!fullVersion || !androidHome) {
core.warning("Unable to link to SDK")
return
}

core.info("Linking to SDK...")

const ndksPath = path.join(androidHome, "ndk")
await mkdir(ndksPath, { recursive: true })

const ndkPath = path.join(ndksPath, fullVersion)
const link = () => symlink(installPath, ndkPath, "dir")

try {
await symlink(installPath, ndkPath, "dir")
await link()
} catch (error) {
const exists =
error &&
typeof error === "object" &&
"code" in error &&
error.code === "EEXIST"
if (!exists) throw error
if (exists) {
await rm(ndkPath, { recursive: true })
await link()
} else {
throw error
}
}
}

Expand Down