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

feat(windows): request folder permissions when traversing path #269

Merged
merged 3 commits into from
May 4, 2024
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
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/io@0.221.0",
"@std/path": "jsr:@std/path@0.221.0",
"@std/streams": "jsr:@std/streams@0.221.0",
"which": "jsr:@david/which@0.3",
"which": "jsr:@david/which@^0.4.1",
"which_runtime": "jsr:@david/which-runtime@0.2"
}
}
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