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

[bug] readDir and createDir don't work in App Dir root level #3580

Closed
Janaka-Steph opened this issue Mar 1, 2022 · 4 comments
Closed

[bug] readDir and createDir don't work in App Dir root level #3580

Janaka-Steph opened this issue Mar 1, 2022 · 4 comments

Comments

@Janaka-Steph
Copy link

Janaka-Steph commented Mar 1, 2022

Describe the bug

fs.readDir and fs.createDir don't work in App Dir root level in 1.0.0-rc, but was working fine in beta.
Those methods work only on a sub-directory of the specified BaseDirectory.

Use case: Checking if App dir exists, creating it otherwise, and write a file in it.

async setItem(key: string, value: any) {
    if ('__TAURI__' in window) {
      try {
        await fs.readDir('', { dir: fs.Dir.App });
      } catch (err) {
        await fs.createDir('', { dir: fs.Dir.App, recursive: true });
      }
      await fs.writeFile(
          { path: getFileNameForKey(key), contents: JSON.stringify(value) },
          { dir: fs.Dir.App }
        )
    }
  }

Here readDir with throw with path not allowed on the configured scope: /Users/stephane/Library/Application Support/tdex-dashboard/, even though it is not a scope issue.

Calling writeFile without checking if app dir exists obviously results in No such file or directory (os error 2) error.

Instead or in addition to fixing readDir/createDir, writeFile could create folder if it doesn' exist.

https://discord.com/channels/616186924390023171/731495028677148753/948156122261495808

Reproduction

No response

Expected behavior

No response

Platform and versions

▶ cargo tauri info

Operating System - Mac OS, version 12.2.1 X64

Node.js environment
  Node.js - 16.14.0
  @tauri-apps/cli - 1.0.0-rc.5
  @tauri-apps/api - 1.0.0-rc.1

Global packages
  npm - 8.1.4
  pnpm - Not installed
  yarn - 1.22.17

Rust environment
  rustup - 1.24.3
  rustc - 1.58.1
  cargo - 1.58.0
  toolchain - stable-aarch64-apple-darwin 

App directory structure
/node_modules
/public
/scripts
/.github
/src-tauri
/build
/.git
/.idea
/src

App
  tauri - 1.0.0-rc.3
  tauri-build - 1.0.0-rc.3
  tao - 0.6.2
  wry - 0.13.2
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../build
  devPath - http://localhost:3003/
  framework - React
  bundler - Webpack

Stack trace

No response

Additional context

No response

@lucasfernog
Copy link
Member

It works if you set your FS scope to ["$APP", "$APP/*"] on the tauri configuration file.

@barbalex
Copy link

barbalex commented Jul 1, 2022

It works if you set your FS scope to ["$APP", "$APP/*"] on the tauri configuration file.

@lucasfernog 1. is that documented? 2. How is it done?

Asking because I ran into this after upgrading from beta version where it worked without.

@lucasfernog
Copy link
Member

The scope was added in the RC versions as a result of the audit. We have the documentation here though it could be improved with this confusion here about reading files vs. directories.

@barbalex
Copy link

barbalex commented Jul 1, 2022

@lucasfernog Thanks a lot, sorry for not finding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants