denoland / deno_cache_dir

Deno CLI's module cache

Home Page:https://jsr.io/@deno/cache-dir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implicit readonly fails if write permission state is set to 'prompt'

jollytoad opened this issue · comments

If the readonly prop of HttpCache is undefined, it's set method attempts to checks for the write permission state, but only if it is 'denied'.
The state may also return prompt, in which case readonly is implicitly set to false, and the method fails with an error...

error: PermissionDenied: Requires write access to "/Users/xxx/Library/Caches/deno/deps/https/deno.land/e7aa7f58f4d432e3bb526431ebe585dae202bf755a689597d2b0abb4780b49ba", run again with the --allow-write flag
    await Deno.writeTextFile(cacheFilename, content, { mode: CACHE_PERM });
    ^
    at async writeFile (deno:runtime/js/40_write_file.js:38:7)
    at async HttpCache.set (file:///Users/mgibson/deno/deno_cache/http_cache.ts:87:5)
    at async FileFetcher.#fetchRemote (file:///Users/mgibson/deno/deno_cache/file_fetcher.ts:224:5)
    at async FileFetcher.fetch (file:///Users/mgibson/deno/deno_cache/file_fetcher.ts:249:24)
    at async fn (file:///Users/mgibson/deno/deno_cache/file_fetcher_test.ts:33:5)

I think it needs to either prompt for write access, or imply that readonly is true. Given that this is cache and it's not vital that the cache is actually written, I'd suggest the most reasonable action would be to imply readonly and not bother the user with an unnecessary prompt.

I'll raise a PR with a test case and fix.

Given that this is cache and it's not vital that the cache is actually written, I'd suggest the most reasonable action would be to imply readonly and not bother the user with an unnecessary prompt.

I don't think we should do this because I think it will cause many people will wonder why the cache is not working or "why does this download every time?"

I don't think we should do this because I think it will cause many people will wonder why the cache is not working or "why does this download every time?"

That's reasonable, but then to allow the cache to be written an --allow-write is required, but opening up a global --allow-write isn't desirable, then it's very difficult to find the cache dir and limit --allow-write to it.

I think for this Deno needs something like an --allow-cache and/or --allow-cache-read/--allow-cache-write to be practical and secure still.

Closing as I can easily work around this now anyway.