Skip to content

Commit

Permalink
Merge pull request #7574 from jandubois/remove-findHome
Browse files Browse the repository at this point in the history
Remove findHome() from scripts/dependencies/tools.ts
  • Loading branch information
mook-as authored Oct 3, 2024
2 parents d3a8e47 + e17c54b commit 5822212
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions scripts/dependencies/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,6 @@ export class KuberlrAndKubectl implements Dependency {
return await downloadFunc(`${ baseURL }/${ archiveName }`, path.join(context.binDir, binName), options);
}

/**
* Find the home directory, in a way that is compatible with kuberlr.
*
* @param onWindows Whether we're running on Windows.
*/
async findHome(onWindows: boolean): Promise<string> {
const tryAccess = async(path: string) => {
try {
await fs.promises.access(path);

return true;
} catch {
return false;
}
};

const osHomeDir = os.homedir();

if (osHomeDir && await tryAccess(osHomeDir)) {
return osHomeDir;
}
if (process.env.HOME && await tryAccess(process.env.HOME)) {
return process.env.HOME;
}
if (onWindows) {
if (process.env.USERPROFILE && await tryAccess(process.env.USERPROFILE)) {
return process.env.USERPROFILE;
}
if (process.env.HOMEDRIVE && process.env.HOMEPATH) {
const homePath = path.join(process.env.HOMEDRIVE, process.env.HOMEPATH);

if (await tryAccess(homePath)) {
return homePath;
}
}
}

throw new Error('Failed to find home directory');
}

/**
* Desired: on Windows, .../bin/kubectl.exe is a copy of .../bin/kuberlr.exe
* elsewhere: .../bin/kubectl is a symlink to .../bin/kuberlr
Expand Down

0 comments on commit 5822212

Please sign in to comment.