Skip to content

[persisted-scope] v2.0.0-alpha - Not persisted after restart ? #849

Open
@Vexcited

Description

@Vexcited

Hi!

I have an issue where the scope isn't getting restored after restarting the application. Wonder if that plugin supports it.
If it doesn't, I'd have to have all the * variations in my fs allow scope but I don't want this for security reasons.

Here's what happening in my main.rs file, nothing special here.

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_persisted_scope::init())
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_dialog::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Then, in my app, I open a directory using the following piece of code :

import { open } from '@tauri-apps/plugin-dialog';
import { documentDir } from '@tauri-apps/api/path';

const selectedFolderPath = await open({
  multiple: false,
  directory: true,
  recursive: true,
  defaultPath: await documentDir()
});

Then I save the path inside localStorage. When the app gets restarted, it reads that value from localStorage and tries to open back the folder with the following function (also used when opening for the first time the folder through open) :

import { readDir } from "@tauri-apps/plugin-fs";

// I kinda liked the API of FileEntry in 1.x, so I tried to reimplement it.
export interface FileEntry {
  name: string;
  path: string;
  children?: Array<FileEntry>;
}

// Since I'm on Windows, I hardwritten this until I find another better way.
const sep = "\\";

export const listRecursivelyFilesInside = async (absolutePath: string): Promise<Array<FileEntry>> => {
  const entries = await readDir(absolutePath);
  const output: Array<FileEntry> = [];
  
  for (const entry of entries) {
    if (entry.isDirectory) {
      const dir = absolutePath + sep + entry.name;
      const entries = await listRecursivelyFilesInside(dir);
    
      output.push({
        name: entry.name,
        path: dir,
        children: entries
      });
    }
    else {
      output.push({
        name: entry.name,
        path: absolutePath + sep + entry.name
      });
    }
  }

  return output;
}

But whenever I restart the app, I get hit by a Error: "forbidden path: C:\\...".
Happens on development and production.

Any idea ? Thanks !

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions