46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
/*
|
|
* // Copyright 2026 zhaoxi826
|
|
* //
|
|
* // Licensed under the Apache License, Version 2.0 (the "License");
|
|
* // you may not use this file except in compliance with the License.
|
|
* // You may obtain a copy of the License at
|
|
* //
|
|
* // http://www.apache.org/licenses/LICENSE-2.0
|
|
* //
|
|
* // Unless required by applicable law or agreed to in writing, software
|
|
* // distributed under the License is distributed on an "AS IS" BASIS,
|
|
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* // See the License for the specific language governing permissions and
|
|
* // limitations under the License.
|
|
*/
|
|
|
|
use anyhow::Result;
|
|
use std::path::Path;
|
|
use std::fs;
|
|
|
|
pub trait Installer {
|
|
fn download(&self) -> Result<()>;
|
|
}
|
|
|
|
pub fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<()> {
|
|
if !dst.exists() {
|
|
fs::create_dir_all(dst)?;
|
|
}
|
|
for entry in fs::read_dir(src)? {
|
|
let entry = entry?;
|
|
let ty = entry.file_type()?;
|
|
let target = dst.join(entry.file_name());
|
|
|
|
// Skip .git directory to avoid unnecessary weight
|
|
if entry.file_name() == ".git" {
|
|
continue;
|
|
}
|
|
|
|
if ty.is_dir() {
|
|
copy_dir_recursive(&entry.path(), &target)?;
|
|
} else {
|
|
fs::copy(&entry.path(), &target)?;
|
|
}
|
|
}
|
|
Ok(())
|
|
} |