Skip to content

Commit 3cfe1bc

Browse files
committed
penambahan informasi disk... (mountpoints)
1 parent 62ae06a commit 3cfe1bc

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tea-partition-api-lib"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
edition = "2021"
55

66
[dependencies]

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub struct Disk {
7777
label: Option<String>,
7878
uuid: Option<String>,
7979
max_partition: u32,
80+
mountpoints: Option<Vec<Value>>,
8081
partitions: Option<Vec<Partition>>,
8182
}
8283

@@ -100,10 +101,15 @@ impl Disk {
100101
label,
101102
uuid,
102103
max_partition,
104+
mountpoints: None,
103105
partitions: None,
104106
}
105107
}
106108

109+
pub fn set_mountpoints(&mut self, input: Option<Vec<Value>>) {
110+
self.mountpoints = input
111+
}
112+
107113
pub fn set_partitions(&mut self, input: Option<Vec<Partition>>) {
108114
self.partitions = input;
109115
}

src/read/get_partition/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ fn parted_get_list_json_general() -> Vec<Disk> {
6262
disk.push(struct_disk);
6363
}
6464

65+
let lsblk = if get_current_uid() != 0 {
66+
cmd!("sudo", "lsblk", "-J")
67+
} else {
68+
cmd!("lsblk", "-J")
69+
};
70+
71+
let lsblk = lsblk.read().expect("gabisa");
72+
73+
let lsblk = serde_json::from_str::<Value>(lsblk.as_str()).unwrap();
74+
75+
let lsblk = lsblk["blockdevices"].as_array().unwrap();
76+
77+
let len_disk = disk.len();
78+
79+
for i in 0..len_disk {
80+
let mountpoints = is_available_vec(lsblk[i]["mountpoints"].as_array());
81+
disk[i].set_mountpoints(mountpoints)
82+
}
83+
6584
disk
6685
}
6786

@@ -138,6 +157,7 @@ pub fn parted_list_partition() -> Vec<Disk> {
138157
if minimum_size > 2048 {
139158
let a_partition: Partition;
140159

160+
// memasukan tambahan nilai dari lsblk
141161
if number_checker != 0 {
142162
let partition_path = &x[number_checker - 1];
143163
let partition_path =

src/read/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl GetDiskInformation for Disk {
2626

2727
impl Clone for Disk {
2828
fn clone(&self) -> Self {
29-
Self { disk_path: self.disk_path.clone(), size: self.size.clone(), model: self.model.clone(), transport: self.transport.clone(), label: self.label.clone(), uuid: self.uuid.clone(), max_partition: self.max_partition.clone(), partitions: self.partitions.clone() }
29+
Self { disk_path: self.disk_path.clone(), size: self.size.clone(), model: self.model.clone(), transport: self.transport.clone(), label: self.label.clone(), uuid: self.uuid.clone(), max_partition: self.max_partition.clone(), mountpoints: self.mountpoints.clone(), partitions: self.partitions.clone() }
3030
}
3131
}
3232

0 commit comments

Comments
 (0)