'Tauri window.__TAURI__.fs.readDir(... is unable to read directory - Error: path not allowed on the configured scope

I'm new to Tauri and I'm trying to read / ls a directory.

window.__TAURI__.fs.readDir("com.tauri.dev/", { dir: window.__TAURI__.fs.Dir.Data }).then(...

Unhandled Promise Rejection: path not allowed on the configured scope: /home/user/.local/share/com.tauri.dev/

It seems like I'm messing up the scope somehow? I've enabled every "allowlist" item I could think of and the scope seems to be defined correctly:

"allowlist": {
  "path": { "all": true },
  "all": true,
  "fs": {
    "all": true,
    "readFile": true,
    "writeFile": true,
    "readDir": true,
    "copyFile": true,
    "createDir": true,
    "removeDir": true,
    "removeFile": true,
    "renameFile": true,
    "scope": ["$DATA/com.tauri.dev/*"]
  }

What gives?


Tauri info:

$ npm run tauri info

> [email protected] tauri
> tauri "info"


Environment
  › OS: Pop!_OS 21.10 X64
  › Node.js: 17.7.0
  › npm: 8.5.2
  › pnpm: Not installed!
  › yarn: 1.22.17
  › rustup: 1.24.3
  › rustc: 1.59.0
  › cargo: 1.59.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.7(outdated, latest: 1.0.0-rc.8)
  › @tauri-apps/api [NPM]: 1.0.0-rc.3(outdated, latest: 1.0.0-rc.3)
  › tauri [RUST]: 1.0.0-rc.6,
  › tauri-build [RUST]: 1.0.0-rc.5,
  › tao [RUST]: 0.7.0,
  › wry [RUST]: 0.14.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:3000/
  › framework: Svelte

App directory structure
  ├─ .vscode
  ├─ js
  ├─ node_modules
  ├─ public
  ├─ css
  ├─ src
  ├─ img
  ├─ src-tauri
  ├─ old_nm
  ├─ doc
  └─ data


Solution 1:[1]

I had similar problems with the scope in http for tauri version 1.0.0-rc.3.

Saw some fixes for the scope on tauri dev and upgraded to an unreleased git backed version (in Cargo.toml):

tauri = { git = "https://github.com/tauri-apps/tauri/", rev="834ccc51539401d36a7dfa1c0982623c9c446a4c", features = ["fs-read-file", "fs-write-file", "http-all",...

Fixed the HTTP issue and also fs is working for me (in tauri.conf.json)

"allowlist": {
            "fs": {
                "readFile": true,
                "writeFile": true,
                "scope": ["$DATA/XXX/**"]
            },

Solution 2:[2]

It seems like it needs both the base path and the one with the * appended in order to work in the directory you are referencing.

"scope": ["$APP/*","$APP"]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 oae
Solution 2 karurochari