Skip to content

Commit

Permalink
fix: fix rename permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
4o3F committed Apr 4, 2024
1 parent 076fe21 commit dd8dc58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 9 additions & 2 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ display-info = "0.5.0" # should be removed after upgrading to tauri v2
dashmap = "5.5.3"
clap = { version = "4.5.4", features = ["derive"] } # add supports for commands
percent-encoding = "2.3.1"
fs_extra = "1.3.0"

[target.'cfg(windows)'.dependencies]
deelevate = "0.2.0"
Expand Down
12 changes: 8 additions & 4 deletions backend/tauri/src/utils/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use crate::{
utils::{dialog::migrate_dialog, dirs, help},
};
use anyhow::Result;
use fs_extra::dir::CopyOptions;
use runas::Command as RunasCommand;
use rust_i18n::t;
use std::{fs, io::ErrorKind, path::PathBuf};
use std::{fs, path::PathBuf};

mod logging;
pub use logging::refresh_logger;
Expand Down Expand Up @@ -196,10 +197,13 @@ pub fn init_service() -> Result<()> {
}

pub fn do_config_migration(old_app_dir: &PathBuf, app_dir: &PathBuf) -> anyhow::Result<()> {
if let Err(e) = fs::rename(old_app_dir, app_dir) {
match e.kind() {
let copy_option = CopyOptions::new();
let copy_option = copy_option.overwrite(true);
let copy_option = copy_option.content_only(true);
if let Err(e) = fs_extra::dir::move_dir(old_app_dir, app_dir, &copy_option) {
match e.kind {
#[cfg(windows)]
ErrorKind::PermissionDenied => {
fs_extra::error::ErrorKind::PermissionDenied => {
// It seems that clash-verge-service is running, so kill it.
let status = RunasCommand::new("cmd")
.args(&["/C", "taskkill", "/IM", "clash-verge-service.exe", "/F"])
Expand Down

0 comments on commit dd8dc58

Please sign in to comment.