Skip to content

Commit

Permalink
Merge pull request #519 from nttld/overwrite
Browse files Browse the repository at this point in the history
Overwrite existing installations when linking to SDK
  • Loading branch information
raftario committed Nov 22, 2023
2 parents aabd401 + e6d76e0 commit e25540e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
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

0 comments on commit e25540e

Please sign in to comment.