Skip to content

Commit

Permalink
feat(windows): request folder permissions when traversing path (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored May 4, 2024
1 parent 3b78fdf commit 0c1cc7b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@std/io": "jsr:@std/[email protected]",
"@std/path": "jsr:@std/[email protected]",
"@std/streams": "jsr:@std/[email protected]",
"which": "jsr:@david/which@0.3",
"which": "jsr:@david/which@^0.4.1",
"which_runtime": "jsr:@david/[email protected]"
}
}
8 changes: 4 additions & 4 deletions deno.lock

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

5 changes: 2 additions & 3 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
"lineWidth": 120
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"**/target",
"target",
"npm",
"**/*.generated.js"
],
"plugins": [
Expand Down
5 changes: 3 additions & 2 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ Deno.test("env should be clean slate when clearEnv is set", async () => {
}
Deno.env.set("DAX_TVAR", "123");
try {
const text = await $`deno eval 'console.log("DAX_TVAR: " + Deno.env.get("DAX_TVAR"))'`.clearEnv().text();
const text = await $`deno eval --no-config 'console.log("DAX_TVAR: " + Deno.env.get("DAX_TVAR"))'`.clearEnv()
.text();
assertEquals(text, "DAX_TVAR: undefined");
} finally {
Deno.env.delete("DAX_TVAR");
Expand All @@ -725,7 +726,7 @@ Deno.test("clearEnv + exportEnv should not clear out real environment", async ()
Deno.env.set("DAX_TVAR", "123");
try {
const text =
await $`deno eval 'console.log("VAR: " + Deno.env.get("DAX_TVAR") + " VAR2: " + Deno.env.get("DAX_TVAR2"))'`
await $`deno eval --no-config 'console.log("VAR: " + Deno.env.get("DAX_TVAR") + " VAR2: " + Deno.env.get("DAX_TVAR2"))'`
.env("DAX_TVAR2", "shake it shake")
.clearEnv()
.exportEnv()
Expand Down
7 changes: 4 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { wasmInstance } from "./src/lib/mod.ts";
import { createPath, Path } from "./src/path.ts";
import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts";
import { outdent } from "./src/vendor/outdent.ts";
import { denoWhichRealEnv } from "./src/shell.ts";

export type { Delay, DelayIterator } from "./src/common.ts";
export { TimeoutError } from "./src/common.ts";
Expand Down Expand Up @@ -510,7 +511,7 @@ export interface $BuiltInProperties<TExtras extends ExtrasObject = {}> {
* or the specified number of retries (`count`) is hit.
*/
withRetries<TReturn>(opts: RetryOptions<TReturn>): Promise<TReturn>;
/** Re-export of `deno_which` for getting the path to an executable. */
/** Re-export of `jsr:@david/which` for getting the path to an executable. */
which: Which;
/** Similar to `which`, but synchronously. */
whichSync: WhichSync;
Expand Down Expand Up @@ -601,14 +602,14 @@ const helperObject = {
if (commandName.toUpperCase() === "DENO") {
return Promise.resolve(Deno.execPath());
} else {
return which(commandName);
return which(commandName, denoWhichRealEnv);
}
},
whichSync(commandName: string) {
if (commandName.toUpperCase() === "DENO") {
return Deno.execPath();
} else {
return whichSync(commandName);
return whichSync(commandName, denoWhichRealEnv);
}
},
};
Expand Down
13 changes: 11 additions & 2 deletions src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,15 @@ async function resolveCommand(unresolvedCommand: UnresolvedCommand, context: Con
};
}

const realEnvironment = new DenoWhichRealEnvironment();
class WhichEnv extends DenoWhichRealEnvironment {
requestPermission(folderPath: string) {
Deno.permissions.requestSync({
name: "read",
path: folderPath,
});
}
}
export const denoWhichRealEnv = new WhichEnv();

export async function whichFromContext(commandName: string, context: {
getVar(key: string): string | undefined;
Expand All @@ -1226,10 +1234,11 @@ export async function whichFromContext(commandName: string, context: {
}
return await which(commandName, {
os: Deno.build.os,
stat: realEnvironment.stat,
stat: denoWhichRealEnv.stat,
env(key) {
return context.getVar(key);
},
requestPermission: denoWhichRealEnv.requestPermission,
});
}

Expand Down

0 comments on commit 0c1cc7b

Please sign in to comment.