-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
39 lines (33 loc) · 1.06 KB
/
build.rs
File metadata and controls
39 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::fs::File;
use std::path::{Path, PathBuf};
use std::{env, fs, io};
use flate2::write::GzEncoder;
use flate2::Compression;
fn get_file_name(path: &Path) -> PathBuf {
let last = path.file_name().unwrap().to_str().unwrap();
let file_name = format!("{}.tar.gz", last);
let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);
out_dir.join(file_name)
}
fn delete_old_archive(path: &Path) {
let archive_path = get_file_name(path);
let _ = fs::remove_file(archive_path);
}
fn compress_dir(path: &Path) -> io::Result<()> {
let archive_path = get_file_name(path);
let tar_gz = File::create(archive_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(".", path)?;
Ok(())
}
fn compress_resources() {
let current_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let res_dir = PathBuf::from(¤t_dir).join("res");
delete_old_archive(&res_dir);
compress_dir(&res_dir).unwrap()
}
fn main() {
compress_resources();
}