Skip to content

Commit 30807da

Browse files
committed
Created an extract-meta feature (for now as a feature)
1 parent d3358c6 commit 30807da

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ edition = "2024"
99
tar = "0.4.44"
1010
flate2 = "1.1.1"
1111
clap = { version = "4.5.37", features = ["derive"] }
12+
13+
[features]
14+
extract-meta = []

src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use clap::Parser;
22
use flate2::read::GzDecoder;
33
use std::collections::HashMap;
44
use std::fs::File;
5+
#[cfg(feature = "extract-meta")]
6+
use std::io::Write;
57
use std::io::{Read, Seek, SeekFrom};
68
use std::path::PathBuf;
79
use tar::{Archive, Entry};
@@ -52,6 +54,26 @@ fn main() {
5254
.read_to_string(&mut buf)
5355
.expect("failed to read asset meta");
5456

57+
#[cfg(feature = "extract-meta")]
58+
{
59+
let path = paths.get(&id).expect("Can't unpack meta with no path");
60+
61+
let parent = path
62+
.parent()
63+
.expect("cannot get parent of root (this should not be possible)");
64+
65+
let meta_file = parent.join(format!(
66+
"{}.meta",
67+
path.file_name()
68+
.expect("no meta filename?")
69+
.to_string_lossy()
70+
));
71+
72+
std::fs::create_dir_all(parent).expect("Failed to unpack");
73+
let mut w = File::create(meta_file).expect("failed to create file");
74+
w.write(buf.as_bytes()).expect("failed to write .meta file");
75+
}
76+
5577
if buf.lines().any(|e| e == "folderAsset: yes") {
5678
paths.remove(&id);
5779
}

0 commit comments

Comments
 (0)