Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc committed Oct 13, 2023
1 parent cddc5a4 commit de0509e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions maa-cli/src/installer/extract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::dirs::Ensure;

use std::{
fs::{self, File},
io::{copy, Read},
path::Path,
path::PathBuf,
fs::File,
io::copy,
path::{Path, PathBuf},
};

use anyhow::{anyhow, bail, Context, Result};
Expand Down Expand Up @@ -103,20 +102,25 @@ fn extract_zip(file: &Path, mapper: impl Fn(&Path) -> Option<PathBuf>) -> Result

#[cfg(unix)]
{
use std::{
fs::remove_file,
io::Read,
os::unix::{ffi::OsStringExt, fs::symlink},
};

const S_IFLNK: u32 = 0o120000;
use std::os::unix::{self, ffi::OsStringExt};

if let Some(mode) = file.unix_mode() {
if mode & S_IFLNK == S_IFLNK {
let mut contents = Vec::new();
file.read_to_end(&mut contents)?;
let link_target = std::ffi::OsString::from_vec(contents);
if outpath.exists() {
fs::remove_file(&outpath).with_context(|| {
remove_file(&outpath).with_context(|| {
format!("Failed to remove existing file: {}", outpath.display())
})?;
}
unix::fs::symlink(link_target, &outpath).with_context(|| {
symlink(link_target, &outpath).with_context(|| {
format!("Failed to extract file: {}", outpath.display())
})?;
continue;
Expand Down

0 comments on commit de0509e

Please sign in to comment.