文件系统
访问文件系统。
🌐 Access the file system.
🌐 Supported Platforms
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | Apps installed via MSI or NSIS in | |
| linux | No write access to | |
| macos | No write access to | |
| android | | Access is restricted to Application folder by default |
| ios | | Access is restricted to Application folder by default |
🌐 Setup
安装 fs 插件即可开始使用。
🌐 Install the fs plugin to get started.
使用项目的包管理器添加依赖:
npm run tauri add fsyarn run tauri add fspnpm tauri add fsdeno task tauri add fsbun tauri add fscargo tauri add fs-
在
src-tauri文件夹中运行以下命令,将插件添加到Cargo.toml中的项目依赖:cargo add tauri-plugin-fs -
修改
lib.rs以初始化插件:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_fs::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
使用你偏好的 JavaScript 包管理器安装 JavaScript Guest 绑定:
npm install @tauri-apps/plugin-fsyarn add @tauri-apps/plugin-fspnpm add @tauri-apps/plugin-fsdeno add npm:@tauri-apps/plugin-fsbun add @tauri-apps/plugin-fs
🌐 Configuration
使用音频、缓存、文档、下载、图片、公共或视频目录时,你的应用必须有权访问外部存储。
🌐 When using the audio, cache, documents, downloads, picture, public or video directories your app must have access to the external storage.
在 gen/android/app/src/main/AndroidManifest.xml 文件中的 manifest 标签中包含以下权限:
🌐 Include the following permissions to the manifest tag in the gen/android/app/src/main/AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Apple 要求应用开发者指定 API 使用批准的原因,以增强用户隐私。
🌐 Apple requires app developers to specify approved reasons for API usage to enhance user privacy.
你必须在 src-tauri/gen/apple 文件夹中创建一个 PrivacyInfo.xcprivacy 文件,并包含所需的 NSPrivacyAccessedAPICategoryFileTimestamp 键和 C617.1 推荐的理由。
🌐 You must create a PrivacyInfo.xcprivacy file in the src-tauri/gen/apple folder
with the required NSPrivacyAccessedAPICategoryFileTimestamp key and the C617.1 recommended reason.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>NSPrivacyAccessedAPITypes</key> <array> <dict> <key>NSPrivacyAccessedAPIType</key> <string>NSPrivacyAccessedAPICategoryFileTimestamp</string> <key>NSPrivacyAccessedAPITypeReasons</key> <array> <string>C617.1</string> </array> </dict> </array> </dict></plist>🌐 Usage
fs 插件同时在 JavaScript 和 Rust 中可用。
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';// when using `"withGlobalTauri": true`, you may use// const { exists, BaseDirectory } = window.__TAURI__.fs;
// Check if the `$APPDATA/avatar.png` file existsawait exists('avatar.png', { baseDir: BaseDirectory.AppData });use tauri_plugin_fs::FsExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_fs::init()) .setup(|app| { // allowed the given directory let scope = app.fs_scope(); scope.allow_directory("/path/to/directory", false); dbg!(scope.allowed());
Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}🌐 Security
此模块防止路径遍历,不允许使用父目录访问符(即不允许使用 “/usr/path/to/../file” 或 ”../path/to/file” 路径)。 通过此 API 访问的路径必须相对于其中一个 基础目录 或使用 path API 创建。
🌐 This module prevents path traversal, not allowing parent directory accessors to be used (i.e. “/usr/path/to/../file” or ”../path/to/file” paths are not allowed). Paths accessed with this API must be either relative to one of the base directories or created with the path API.
有关更多信息,请参阅 [@tauri-apps/plugin-fs - 安全]。
🌐 See @tauri-apps/plugin-fs - Security for more information.
🌐 Paths
文件系统插件提供两种操作路径的方法:[基本目录]和[路径 API]。
🌐 The file system plugin offers two ways of manipulating paths: the base directory and the path API.
-
基本目录
每个 API 都有一个 options 参数,它允许你定义一个 基础目录,该 基础目录 作为操作的工作目录。
import { readFile } from '@tauri-apps/plugin-fs';const contents = await readFile('avatars/tauri.png', {baseDir: BaseDirectory.Home,});在上面的例子中,由于我们使用的是 Home 基目录,因此会读取 ~/avatars/tauri.png 文件。
-
路径 API
或者,你可以使用路径 API 来执行路径操作。
import { readFile } from '@tauri-apps/plugin-fs';import * as path from '@tauri-apps/api/path';const home = await path.homeDir();const contents = await readFile(await path.join(home, 'avatars/tauri.png'));
🌐 Files
🌐 Create
创建一个文件并返回它的句柄。如果文件已存在,则会被截断。
🌐 Creates a file and returns a handle to it. If the file already exists, it is truncated.
import { create, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await create('foo/bar.txt', { baseDir: BaseDirectory.AppData });await file.write(new TextEncoder().encode('Hello world'));await file.close();在操作完文件后,请始终调用 file.close()。
🌐 Write
该插件提供单独的 API 用于写入文本和二进制文件以提高性能。
🌐 The plugin offers separate APIs for writing text and binary files for performance.
-
文本文件
import { writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = JSON.stringify({ notifications: true });await writeTextFile('config.json', contents, {baseDir: BaseDirectory.AppConfig,}); -
二进制文件
import { writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = new Uint8Array(); // fill a byte arrayawait writeFile('config', contents, {baseDir: BaseDirectory.AppConfig,});
🌐 Open
打开一个文件并返回其句柄。使用此 API,你可以更好地控制文件的打开方式(只读模式、只写模式、追加而不是覆盖、仅当文件不存在时创建等)。
🌐 Opens a file and returns a handle to it. With this API you have more control over how the file should be opened (read-only mode, write-only mode, append instead of overwrite, only create if it does not exist, etc).
在操作完文件后,请始终调用 file.close()。
-
read-only
这是默认模式。
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {read: true,baseDir: BaseDirectory.AppData,});const stat = await file.stat();const buf = new Uint8Array(stat.size);await file.read(buf);const textContents = new TextDecoder().decode(buf);await file.close(); -
write-only
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('Hello world'));await file.close();默认情况下,文件在任何
file.write()调用时都会被截断。请参见以下示例以了解如何改为附加到现有内容。 -
append
import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {append: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();请注意,
{ append: true }的效果与{ write: true, append: true }相同。 -
truncate
当设置
truncate选项且文件已存在时,它将被截断为长度 0。import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,truncate: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();此选项要求
write为true。如果你想使用多个
file.write()调用重写现有文件,你可以将其与append选项一起使用。 -
create
默认情况下,
openAPI 仅打开现有文件。要在文件不存在时创建它,如果存在则打开它,请将create设置为true:import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,create: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();为了创建该文件,
write或append也必须设置为true。如果文件已存在而失败,请参阅
createNew。 -
createNew
createNew的工作方式类似于create,但如果文件已存在则会失败。import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open('foo/bar.txt', {write: true,createNew: true,baseDir: BaseDirectory.AppData,});await file.write(new TextEncoder().encode('world'));await file.close();为了创建该文件,
write也必须设置为true。
🌐 Read
该插件提供单独的 API 用于读取文本和二进制文件以提高性能。
🌐 The plugin offers separate APIs for reading text and binary files for performance.
-
文本文件
import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';const configToml = await readTextFile('config.toml', {baseDir: BaseDirectory.AppConfig,});如果文件很大,你可以使用
readTextFileLinesAPI 流式读取其行:import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';const lines = await readTextFileLines('app.logs', {baseDir: BaseDirectory.AppLog,});for await (const line of lines) {console.log(line);} -
二进制文件
import { readFile, BaseDirectory } from '@tauri-apps/plugin-fs';const icon = await readFile('icon.png', {baseDir: BaseDirectory.Resources,});
🌐 Remove
调用 remove() 删除文件。如果文件不存在,将返回错误。
🌐 Call remove() to delete a file. If the file does not exist, an error is returned.
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('user.db', { baseDir: BaseDirectory.AppLocalData });🌐 Copy
copyFile 函数接受源路径和目标路径。请注意,你必须单独配置每个基础目录。
🌐 The copyFile function takes the source and destination paths.
Note that you must configure each base directory separately.
import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';await copyFile('user.db', 'user.db.bk', { fromPathBaseDir: BaseDirectory.AppLocalData, toPathBaseDir: BaseDirectory.Temp,});在上述示例中,<app-local-data>/user.db 文件被复制到 $TMPDIR/user.db.bk。
🌐 Exists
使用 exists() 函数来检查文件是否存在:
🌐 Use the exists() function to check if a file exists:
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';const tokenExists = await exists('token', { baseDir: BaseDirectory.AppLocalData,});🌐 Metadata
可以使用 stat 和 lstat 函数检索文件元数据。stat 会跟随符号链接(如果它指向的实际文件不在允许范围内,则返回错误),而 lstat 不会跟随符号链接,返回符号链接本身的信息。
🌐 File metadata can be retrieved with the stat and the lstat functions.
stat follows symlinks (and returns an error if the actual file it points to is not allowed by the scope)
and lstat does not follow symlinks, returning the information of the symlink itself.
import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';const metadata = await stat('app.db', { baseDir: BaseDirectory.AppLocalData,});🌐 Rename
rename 函数接受源路径和目标路径。请注意,你必须单独配置每个基础目录。
🌐 The rename function takes the source and destination paths.
Note that you must configure each base directory separately.
import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';await rename('user.db.bk', 'user.db', { fromPathBaseDir: BaseDirectory.AppLocalData, toPathBaseDir: BaseDirectory.Temp,});在上述示例中,<app-local-data>/user.db.bk 文件被重命名为 $TMPDIR/user.db。
🌐 Truncate
截断或扩展指定的文件以达到指定的文件长度(默认为 0)。
🌐 Truncates or extends the specified file to reach the specified file length (defaults to 0).
- 截断为 0 长度
import { truncate } from '@tauri-apps/plugin-fs';await truncate('my_file.txt', 0, { baseDir: BaseDirectory.AppLocalData });- 截断为特定长度
import { truncate, readTextFile, writeTextFile, BaseDirectory,} from '@tauri-apps/plugin-fs';
const filePath = 'file.txt';await writeTextFile(filePath, 'Hello World', { baseDir: BaseDirectory.AppLocalData,});await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData,});const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData,});console.log(data); // "Hello W"🌐 Directories
🌐 Create
要创建一个目录,调用 mkdir 函数:
🌐 To create a directory, call the mkdir function:
import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';await mkdir('images', { baseDir: BaseDirectory.AppLocalData,});🌐 Read
readDir 函数递归列出目录的条目:
🌐 The readDir function recursively lists the entries of a directory:
import { readDir, BaseDirectory } from '@tauri-apps/plugin-fs';const entries = await readDir('users', { baseDir: BaseDirectory.AppLocalData });🌐 Remove
调用 remove() 删除目录。如果目录不存在,将返回错误。
🌐 Call remove() to delete a directory. If the directory does not exist, an error is returned.
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('images', { baseDir: BaseDirectory.AppLocalData });如果目录不为空,必须将 recursive 选项设置为 true:
🌐 If the directory is not empty, the recursive option must be set to true:
import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('images', { baseDir: BaseDirectory.AppLocalData, recursive: true,});🌐 Exists
使用 exists() 函数来检查目录是否存在:
🌐 Use the exists() function to check if a directory exists:
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';const tokenExists = await exists('images', { baseDir: BaseDirectory.AppLocalData,});🌐 Metadata
可以使用 stat 和 lstat 函数检索目录元数据。stat 会跟随符号链接(如果它指向的实际文件不在允许范围内,则返回错误),而 lstat 不会跟随符号链接,返回符号链接本身的信息。
🌐 Directory metadata can be retrieved with the stat and the lstat functions.
stat follows symlinks (and returns an error if the actual file it points to is not allowed by the scope)
and lstat does not follow symlinks, returning the information of the symlink itself.
import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';const metadata = await stat('databases', { baseDir: BaseDirectory.AppLocalData,});🌐 Watching changes
要监视目录或文件的更改,请使用 watch 或 watchImmediate 函数。
🌐 To watch a directory or file for changes, use the watch or watchImmediate functions.
-
watch
watch经过防抖处理,因此它只会在一定延迟后触发事件:import { watch, BaseDirectory } from '@tauri-apps/plugin-fs';await watch('app.log',(event) => {console.log('app.log event', event);},{baseDir: BaseDirectory.AppLog,delayMs: 500,}); -
watchImmediate
watchImmediate立即通知监听器事件:import { watchImmediate, BaseDirectory } from '@tauri-apps/plugin-fs';await watchImmediate('logs',(event) => {console.log('logs directory event', event);},{baseDir: BaseDirectory.AppLog,recursive: true,});
默认情况下,对目录的监视操作不是递归的。将 recursive 选项设置为 true 可以递归地监视所有子目录的变化。
🌐 By default watch operations on a directory are not recursive.
Set the recursive option to true to recursively watch for changes on all sub-directories.
监视功能需要 watch 功能标志:
[dependencies]tauri-plugin-fs = { version = "2.0.0", features = ["watch"] }🌐 Permissions
默认情况下,所有潜在危险的插件命令和作用域都会被阻止,无法访问。你必须在 capabilities 配置中修改权限以启用这些功能。
🌐 By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities configuration to enable these.
有关更多信息,请参见功能概览,有关使用插件权限的分步指南,请参见分步指南。
🌐 See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ "fs:default", { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}Default Permission
This set of permissions describes the what kind of
file system access the fs plugin has enabled or denied by default.
Granted Permissions
This default permission set enables read access to the application specific directories (AppConfig, AppData, AppLocalData, AppCache, AppLog) and all files and sub directories created in it. The location of these directories depends on the operating system, where the application is run.
In general these directories need to be manually created by the application at runtime, before accessing files or folders in it is possible.
Therefore, it is also allowed to create all of these folders via
the mkdir command.
Denied Permissions
This default permission set prevents access to critical components of the Tauri application by default. On Windows the webview data folder access is denied.
This default permission set includes the following:
create-app-specific-dirsread-app-specific-dirs-recursivedeny-default
Permission Table
| Identifier | Description |
|---|---|
|
|
This allows full recursive read access to the complete application folders, files and subdirectories. |
|
|
This allows full recursive write access to the complete application folders, files and subdirectories. |
|
|
This allows non-recursive read access to the application folders. |
|
|
This allows non-recursive write access to the application folders. |
|
|
This allows full recursive read access to metadata of the application folders, including file listing and statistics. |
|
|
This allows non-recursive read access to metadata of the application folders, including file listing and statistics. |
|
|
This scope permits recursive access to the complete application folders, including sub directories and files. |
|
|
This scope permits access to all files and list content of top level directories in the application folders. |
|
|
This scope permits to list all files and folders in the application directories. |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
Enables the copy_file command without any pre-configured scope. |
|
|
Denies the copy_file command without any pre-configured scope. |
|
|
Enables the create command without any pre-configured scope. |
|
|
Denies the create command without any pre-configured scope. |
|
|
Enables the exists command without any pre-configured scope. |
|
|
Denies the exists command without any pre-configured scope. |
|
|
Enables the fstat command without any pre-configured scope. |
|
|
Denies the fstat command without any pre-configured scope. |
|
|
Enables the ftruncate command without any pre-configured scope. |
|
|
Denies the ftruncate command without any pre-configured scope. |
|
|
Enables the lstat command without any pre-configured scope. |
|
|
Denies the lstat command without any pre-configured scope. |
|
|
Enables the mkdir command without any pre-configured scope. |
|
|
Denies the mkdir command without any pre-configured scope. |
|
|
Enables the open command without any pre-configured scope. |
|
|
Denies the open command without any pre-configured scope. |
|
|
Enables the read command without any pre-configured scope. |
|
|
Denies the read command without any pre-configured scope. |
|
|
Enables the read_dir command without any pre-configured scope. |
|
|
Denies the read_dir command without any pre-configured scope. |
|
|
Enables the read_file command without any pre-configured scope. |
|
|
Denies the read_file command without any pre-configured scope. |
|
|
Enables the read_text_file command without any pre-configured scope. |
|
|
Denies the read_text_file command without any pre-configured scope. |
|
|
Enables the read_text_file_lines command without any pre-configured scope. |
|
|
Denies the read_text_file_lines command without any pre-configured scope. |
|
|
Enables the read_text_file_lines_next command without any pre-configured scope. |
|
|
Denies the read_text_file_lines_next command without any pre-configured scope. |
|
|
Enables the remove command without any pre-configured scope. |
|
|
Denies the remove command without any pre-configured scope. |
|
|
Enables the rename command without any pre-configured scope. |
|
|
Denies the rename command without any pre-configured scope. |
|
|
Enables the seek command without any pre-configured scope. |
|
|
Denies the seek command without any pre-configured scope. |
|
|
Enables the size command without any pre-configured scope. |
|
|
Denies the size command without any pre-configured scope. |
|
|
Enables the start_accessing_security_scoped_resource command without any pre-configured scope. |
|
|
Denies the start_accessing_security_scoped_resource command without any pre-configured scope. |
|
|
Enables the stat command without any pre-configured scope. |
|
|
Denies the stat command without any pre-configured scope. |
|
|
Enables the stop_accessing_security_scoped_resource command without any pre-configured scope. |
|
|
Denies the stop_accessing_security_scoped_resource command without any pre-configured scope. |
|
|
Enables the truncate command without any pre-configured scope. |
|
|
Denies the truncate command without any pre-configured scope. |
|
|
Enables the unwatch command without any pre-configured scope. |
|
|
Denies the unwatch command without any pre-configured scope. |
|
|
Enables the watch command without any pre-configured scope. |
|
|
Denies the watch command without any pre-configured scope. |
|
|
Enables the write command without any pre-configured scope. |
|
|
Denies the write command without any pre-configured scope. |
|
|
Enables the write_file command without any pre-configured scope. |
|
|
Denies the write_file command without any pre-configured scope. |
|
|
Enables the write_text_file command without any pre-configured scope. |
|
|
Denies the write_text_file command without any pre-configured scope. |
|
|
This permissions allows to create the application specific directories. |
|
|
This denies access to dangerous Tauri relevant files and folders by default. |
|
|
This denies read access to the
|
|
|
This denies read access to the
|
|
|
This enables all read related commands without any pre-configured accessible paths. |
|
|
This permission allows recursive read functionality on the application specific base directories. |
|
|
This enables directory read and file metadata related commands without any pre-configured accessible paths. |
|
|
This enables file read related commands without any pre-configured accessible paths. |
|
|
This enables all index or metadata related commands without any pre-configured accessible paths. |
|
|
An empty permission you can use to modify the global scope. Example
|
|
|
This enables all write related commands without any pre-configured accessible paths. |
|
|
This enables all file write related commands without any pre-configured accessible paths. |
🌐 Scopes
此插件权限包括用于定义允许或明确拒绝的路径的作用域。有关作用域的更多信息,请参见[命令作用域]。
🌐 This plugin permissions includes scopes for defining which paths are allowed or explicitly rejected. For more information on scopes, see the Command Scopes.
每个 allow 或 deny 范围必须包含一个数组,列出所有应被允许或拒绝的路径。范围条目采用 { path: string } 格式。
🌐 Each allow or deny scope must include an array listing all paths that should be allowed or denied.
The scope entries are in the { path: string } format.
deny 优先于 allow,所以如果一个路径被某个作用域拒绝,它在运行时将被阻止,即使它被另一个作用域允许。
作用域条目可以使用 $<path> 变量来引用常见的系统路径,例如主目录、应用资源目录和配置目录。下表列出了你可以引用的所有常见路径:
🌐 Scope entries can use $<path> variables to reference common system paths such as the home directory,
the app resources directory and the config directory. The following table lists all common paths you can reference:
| 路径 | 变量 |
|---|---|
| appConfigDir | $APPCONFIG |
| appDataDir | $APPDATA |
| appLocalDataDir | $APPLOCALDATA |
| appcacheDir | $APPCACHE |
| applogDir | $APPLOG |
| 音频目录 | $AUDIO |
| cacheDir | $CACHE |
| configDir | $CONFIG |
| dataDir | $DATA |
| localDataDir | $LOCALDATA |
| desktopDir | $DESKTOP |
| documentDir | $DOCUMENT |
| 下载目录 | $DOWNLOAD |
| 可执行文件目录 | $EXE |
| fontDir | $字体 |
| homeDir | $HOME |
| 图片目录 | $PICTURE |
| publicDir | $PUBLIC |
| runtimeDir | $RUNTIME |
| templateDir | $TEMPLATE |
| 视频目录 | $VIDEO |
| resourceDir | $RESOURCE |
| tempDir | $TEMP |
🌐 Examples
- 全局范围
要将作用域应用于任何 fs 命令,请使用 fs:scope 权限:
🌐 To apply a scope to any fs command, use the fs:scope permission:
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA" }, { "path": "$APPDATA/**/*" }] } ]}要将范围应用于特定的 fs 命令,请使用权限的对象形式 { "identifier": string, "allow"?: [], "deny"?: [] }:
🌐 To apply a scope to a specific fs command,
use the the object form of permissions { "identifier": string, "allow"?: [], "deny"?: [] }:
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:allow-rename", "allow": [{ "path": "$HOME/**/*" }] }, { "identifier": "fs:allow-rename", "deny": [{ "path": "$HOME/.config/**/*" }] }, { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}在上面的示例中,你可以使用 exists API,使用任何 $APPDATA 子路径(不包括子目录)和 rename
🌐 In the above example you can use the exists API using any $APPDATA sub path (does not include sub-directories)
and the rename
如果你试图在基于 Unix 的系统上访问点文件(例如 .gitignore)或点文件夹(例如 .ssh),那么你需要指定完整路径 /home/user/.ssh/example 或点文件夹路径组件后的通配符 /home/user/.ssh/*。
如果在你的使用场景中这不起作用,那么你可以配置插件将任何组件视为有效的路径字面量。
🌐 If that does not work in your use case then you can configure the plugin to treat any component as a valid path literal.
"plugins": { "fs": { "requireLiteralLeadingDot": false } }Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站