tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.53k stars 2.58k forks source link

[bug] tauri_plugin_fs #11570

Closed vansAir closed 3 weeks ago

vansAir commented 3 weeks ago

Describe the bug

When I use tokio::fs::rename, I am prompted with "Access denied.os error (5)". How can I give it administrator permissions? I am using the Windows 11 operating system. I tried to execute it using cmd and printed the execution statement. In Rust, it shows exit code 1, but it can be executed directly in cmd.Later, I used tauri_plugin_fs. Still, there is a permission error.

import { rename} from '@tauri-apps/plugin-fs';
const name = ref("D:\\SPACE\\mes\\"); 
const names = ref("mes-main,mes-mcdc,mes-mcsm"); 
const packageMsg = ref("");
const progress = ref(0); 
console.log(rename("D:\\\\SPACE\\mes\\\\mes-mcdc\\mcdc\\1.txt","D:\\\\SPACE\\mes\\\\mes-main\\dist\\child"))

default.json

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Capability for the main window",
  "windows": [
    "main"
  ],
  "permissions": [
    "core:default",
    "shell:allow-open",
    "fs:write-files",
    "fs:read-files",
    {
      "identifier": "fs:allow-rename",
      "allow": [{ "path":"$HOME/**" }]
    }
  ]
}

Reproduction

No response

Expected behavior

The folder can be moved normally

Full tauri info output

index.js:528  Uncaught (in promise) forbidden path: D:\\SPACE\mes\\mes-mcdc\mcdc\1.txt
2App.vue:51  
Failed to copy files: 拒绝访问。 (os error 5)

Stack trace

No response

Additional context

No response

x6eull commented 3 weeks ago

It seems that you are using extra backslashes. The path would be interpreted as D:\\SPACE\mes\\mes-mcdc\mcdc\1.txt and it tends to be invalid. To deal with forbidden path error:

{
      "identifier": "fs:allow-rename",
      "allow": ["D:\\**"]
}
vansAir commented 3 weeks ago

It seems that you are using extra backslashes. The path would be interpreted as D:\\SPACE\mes\\mes-mcdc\mcdc\1.txt and it tends to be invalid.您似乎使用了额外的反斜杠。该路径将被解释为 D:\\SPACE\mes\\mes-mcdc\mcdc\1.txt 而且它往往是无效的。 To deal with forbidden path error:处理forbidden path错误:

{
      "identifier": "fs:allow-rename",
      "allow": ["D:\\**"]
}

22

Please take a look at this error. Thank you very much.

x6eull commented 3 weeks ago
  1. Disable your antivirus software.
  2. Run IDE as Administrator.
vansAir commented 3 weeks ago
  1. Disable your antivirus software.禁用您的防病毒软件。
  2. Run IDE as Administrator.以管理员身份运行 IDE。

This is my configuration itself, but it still doesn't work. :=(

Legend-Master commented 3 weeks ago

D:\SPACE\mes\mes-main\dist\child seems like a directory that already exists? If that's the case, you can't replace a directory with a file using rename, if you want to move the file under this directory, you need to write the whole path like D:\SPACE\mes\mes-main\dist\child\1.txt

Anyways, this is not related tauri's fs plugin, check https://doc.rust-lang.org/std/fs/fn.rename.html for how rename works