Compare commits

..

No commits in common. "master" and "ci_build_ipbinding" have entirely different histories.

8 changed files with 12 additions and 194 deletions

View File

@ -31,10 +31,6 @@ rust-latest:
paths: paths:
- "./raid_manager_static" - "./raid_manager_static"
- "./raid_manager" - "./raid_manager"
cache:
key: shared-rust-latest-cache
paths:
- lib/target/
rust-nightly: rust-nightly:
stage: build_backend stage: build_backend
@ -46,7 +42,3 @@ rust-nightly:
- cargo build -r --manifest-path=lib/Cargo.toml - cargo build -r --manifest-path=lib/Cargo.toml
- cargo test -r --manifest-path=lib/Cargo.toml - cargo test -r --manifest-path=lib/Cargo.toml
allow_failure: true allow_failure: true
cache:
key: shared-rust-nightly-cache
paths:
- lib/target/

View File

@ -59,7 +59,7 @@ class _DiskPageState extends State<DiskPage> {
), ),
onTap: () { onTap: () {
Provider.of<BreadCrumbController>(context, listen: false) Provider.of<BreadCrumbController>(context, listen: false)
.pushPage(DiskInfoPage(disk: data[idx]), data[idx].name); .pushPage(const DiskInfoPage(), data[idx].name);
}, },
); );
}, },

View File

@ -6,9 +6,8 @@ part 'disk.g.dart';
class Disk { class Disk {
String name; String name;
int size; int size;
List<String> mountpoints;
Disk(this.name, this.size, this.mountpoints); Disk(this.name, this.size);
factory Disk.fromJson(Map<String, dynamic> json) => _$DiskFromJson(json); factory Disk.fromJson(Map<String, dynamic> json) => _$DiskFromJson(json);
Map<String, dynamic> toJson() => _$DiskToJson(this); Map<String, dynamic> toJson() => _$DiskToJson(this);
} }

View File

@ -9,11 +9,9 @@ part of 'disk.dart';
Disk _$DiskFromJson(Map<String, dynamic> json) => Disk( Disk _$DiskFromJson(Map<String, dynamic> json) => Disk(
json['name'] as String, json['name'] as String,
json['size'] as int, json['size'] as int,
(json['mountpoints'] as List<dynamic>).map((e) => e as String).toList(),
); );
Map<String, dynamic> _$DiskToJson(Disk instance) => <String, dynamic>{ Map<String, dynamic> _$DiskToJson(Disk instance) => <String, dynamic>{
'name': instance.name, 'name': instance.name,
'size': instance.size, 'size': instance.size,
'mountpoints': instance.mountpoints,
}; };

View File

@ -1,13 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:raid_manager/utils/file_formatter.dart';
import '../breadcrumb_page/breadcrumb_controller.dart'; import '../breadcrumb_page/breadcrumb_controller.dart';
import '../types/disk.dart';
class DiskInfoPage extends StatefulWidget { class DiskInfoPage extends StatefulWidget {
const DiskInfoPage({Key? key, required this.disk}) : super(key: key); const DiskInfoPage({Key? key}) : super(key: key);
final Disk disk;
@override @override
State<DiskInfoPage> createState() => _DiskInfoPageState(); State<DiskInfoPage> createState() => _DiskInfoPageState();
@ -17,14 +14,8 @@ class _DiskInfoPageState extends State<DiskInfoPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text("Name:",style: Theme.of(context).textTheme.labelMedium), const Text("Mysupercool page"),
Text(widget.disk.name,style: Theme.of(context).textTheme.labelMedium),
Text("Size:",style: Theme.of(context).textTheme.labelMedium),
Text(widget.disk.size.readableFileSize(),style: Theme.of(context).textTheme.labelMedium),
Text("Mountpoints:",style: Theme.of(context).textTheme.labelMedium),
Text(widget.disk.mountpoints.toString(),style: Theme.of(context).textTheme.labelMedium),
TextButton( TextButton(
onPressed: () { onPressed: () {
Provider.of<BreadCrumbController>(context, listen: false) Provider.of<BreadCrumbController>(context, listen: false)

36
lib/Cargo.lock generated
View File

@ -573,15 +573,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.4" version = "1.0.4"
@ -655,12 +646,6 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.5" version = "0.8.5"
@ -693,16 +678,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "nom"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.46.0"
@ -863,7 +838,6 @@ dependencies = [
"regex", "regex",
"rocket", "rocket",
"rust-embed", "rust-embed",
"versions",
] ]
[[package]] [[package]]
@ -1482,16 +1456,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "versions"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee97e1d97bd593fb513912a07691b742361b3dd64ad56f2c694ea2dbfe0665d3"
dependencies = [
"itertools",
"nom",
]
[[package]] [[package]]
name = "walkdir" name = "walkdir"
version = "2.3.2" version = "2.3.2"

View File

@ -9,7 +9,6 @@ regex = "1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
include_dir = "0.7.3" include_dir = "0.7.3"
rust-embed = "6.4.2" rust-embed = "6.4.2"
versions = "4.1.0"
[features] [features]
static = [] static = []

View File

@ -1,17 +1,12 @@
use std::process::Command; use std::process::Command;
use lazy_static::lazy_static;
use regex::{Regex};
use rocket::serde::json::{serde_json}; use rocket::serde::json::{serde_json};
use rocket::serde::{Serialize, Deserialize}; use rocket::serde::{Serialize, Deserialize};
use versions::Versioning;
#[derive(Serialize)] #[derive(Serialize)]
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
pub struct Disk { pub struct Disk {
name: String, name: String,
size: u64, size: u64,
mountpoints: Vec<String>
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -25,10 +20,7 @@ struct ChildDevice {
ro: bool, ro: bool,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: String, kind: String,
// new version is with vec of mountpoints mountpoints: Vec<Option<String>>,
mountpoints: Option<Vec<Option<String>>>,
// old version is with one single mountpoint
mountpoint: Option<String>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -42,10 +34,7 @@ struct Blockdevice {
majmin: String, majmin: String,
rm: bool, rm: bool,
ro: bool, ro: bool,
// new version is with vec of mountpoints mountpoints: Vec<Option<String>>,
mountpoints: Option<Vec<Option<String>>>,
// old version is with one single mountpoint
mountpoint: Option<String>,
children: Option<Vec<ChildDevice>>, children: Option<Vec<ChildDevice>>,
} }
@ -55,63 +44,6 @@ struct LsblkT {
blockdevices: Vec<Blockdevice>, blockdevices: Vec<Blockdevice>,
} }
fn lsblk_version() -> Versioning {
let output = Command::new("lsblk")
.arg("--version")
.output()
.expect("failed to execute process");
let out = output.stdout;
let out = String::from_utf8(out).unwrap();
lazy_static! {
static ref RE: Regex = Regex::new(r"([0-9]+\.[0-9]+\.[0-9]+)$").unwrap();
}
match RE.captures(&out) {
None => Versioning::default(),
Some(res) => {
if res.len() == 2 {
match Versioning::new(&res[1]){
None => Versioning::default(),
Some(v) => v
}
}else{
Versioning::default()
}
}
}
}
fn parse_lsblk_str(out: String) -> Vec<Disk> {
let v: LsblkT = serde_json::from_str(out.as_str()).unwrap();
let version = lsblk_version();
let mut disks: Vec<Disk> = Vec::new();
for d in v.blockdevices {
if d.kind != "disk" { continue; };
let mut mountpoints: Vec<String> = Vec::new();
if version < Versioning::new("2.37.0").unwrap() {
if d.mountpoint.is_some() {
mountpoints.push(d.mountpoint.unwrap())
}
} else{
if d.mountpoints.is_some() {
let mntpts = d.mountpoints.unwrap();
for p in mntpts {
if p.is_some() {
mountpoints.push(p.unwrap())
}
}
}
}
disks.push(Disk { name: d.name, size: d.size, mountpoints });
}
return disks;
}
pub fn parse_lsblk() -> Vec<Disk> { pub fn parse_lsblk() -> Vec<Disk> {
let output = Command::new("lsblk") let output = Command::new("lsblk")
.arg("-J") .arg("-J")
@ -122,70 +54,13 @@ pub fn parse_lsblk() -> Vec<Disk> {
let out = output.stdout; let out = output.stdout;
let out = String::from_utf8(out).unwrap(); let out = String::from_utf8(out).unwrap();
parse_lsblk_str(out)
}
#[cfg(test)] let v: LsblkT = serde_json::from_str(out.as_str()).unwrap();
mod tests {
use rocket::serde::json::serde_json::json;
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test] let mut disks: Vec<Disk> = Vec::new();
fn test_empty() { for d in v.blockdevices {
assert_eq!(json!(parse_lsblk_str(r#" if d.kind != "disk" { continue; };
{ disks.push(Disk { name: d.name, size: d.size });
"blockdevices": [
{"name":"/dev/loop0", "maj:min":"7:0", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop1", "maj:min":"7:1", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop2", "maj:min":"7:2", "rm":false, "size":107374182400, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop3", "maj:min":"7:3", "rm":false, "size":10737418240, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop4", "maj:min":"7:4", "rm":false, "size":34359738368, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop5", "maj:min":"7:5", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop6", "maj:min":"7:6", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop7", "maj:min":"7:7", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop8", "maj:min":"7:8", "rm":false, "size":32212254720, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop9", "maj:min":"7:9", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop10", "maj:min":"7:10", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop11", "maj:min":"7:11", "rm":false, "size":12884901888, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/loop12", "maj:min":"7:12", "rm":false, "size":8589934592, "ro":false, "type":"loop", "mountpoint":null},
{"name":"/dev/sda", "maj:min":"8:0", "rm":false, "size":120034123776, "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"/dev/sda1", "maj:min":"8:1", "rm":false, "size":1031168, "ro":false, "type":"part", "mountpoint":null},
{"name":"/dev/sda2", "maj:min":"8:2", "rm":false, "size":536870912, "ro":false, "type":"part", "mountpoint":null},
{"name":"/dev/sda3", "maj:min":"8:3", "rm":false, "size":119496187392, "ro":false, "type":"part", "mountpoint":null,
"children": [
{"name":"/dev/mapper/pve-swap", "maj:min":"253:0", "rm":false, "size":4294967296, "ro":false, "type":"lvm", "mountpoint":"[SWAP]"},
{"name":"/dev/mapper/pve-root", "maj:min":"253:1", "rm":false, "size":115196559360, "ro":false, "type":"lvm", "mountpoint":"/"}
]
}
]
},
{"name":"/dev/sdb", "maj:min":"8:16", "rm":false, "size":3000592982016, "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"/dev/md127", "maj:min":"9:127", "rm":false, "size":9001376219136, "ro":false, "type":"raid5", "mountpoint":"/media/3TBRaid"}
]
},
{"name":"/dev/sdc", "maj:min":"8:32", "rm":false, "size":3000592982016, "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"/dev/md127", "maj:min":"9:127", "rm":false, "size":9001376219136, "ro":false, "type":"raid5", "mountpoint":"/media/3TBRaid"}
]
},
{"name":"/dev/sdd", "maj:min":"8:48", "rm":false, "size":4000787030016, "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"/dev/md127", "maj:min":"9:127", "rm":false, "size":9001376219136, "ro":false, "type":"raid5", "mountpoint":"/media/3TBRaid"}
]
},
{"name":"/dev/sde", "maj:min":"8:64", "rm":false, "size":240057409536, "ro":false, "type":"disk", "mountpoint":"/media/hdd1"},
{"name":"/dev/sdf", "maj:min":"8:80", "rm":false, "size":120034123776, "ro":false, "type":"disk", "mountpoint":"/media/hdd2"},
{"name":"/dev/sdg", "maj:min":"8:96", "rm":false, "size":3000592982016, "ro":false, "type":"disk", "mountpoint":null,
"children": [
{"name":"/dev/md127", "maj:min":"9:127", "rm":false, "size":9001376219136, "ro":false, "type":"raid5", "mountpoint":"/media/3TBRaid"}
]
},
{"name":"/dev/nvme0n1", "maj:min":"259:0", "rm":false, "size":1000204886016, "ro":false, "type":"disk", "mountpoint":"/media/hdd3"}
]
}
"#.to_string())).to_string(), r#"[{"mountpoints":[],"name":"/dev/sda","size":120034123776},{"mountpoints":[],"name":"/dev/sdb","size":3000592982016},{"mountpoints":[],"name":"/dev/sdc","size":3000592982016},{"mountpoints":[],"name":"/dev/sdd","size":4000787030016},{"mountpoints":["/media/hdd1"],"name":"/dev/sde","size":240057409536},{"mountpoints":["/media/hdd2"],"name":"/dev/sdf","size":120034123776},{"mountpoints":[],"name":"/dev/sdg","size":3000592982016},{"mountpoints":["/media/hdd3"],"name":"/dev/nvme0n1","size":1000204886016}]"#);
} }
return disks;
} }