Skip to content

Commit fcea7c8

Browse files
author
Francesco Cogno
authored
Merge pull request #1 from scatenag/master
Added "user" label
2 parents 5263975 + 2c14dd6 commit fcea7c8

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "prometheus_folder_size_exporter"
3-
version = "0.1.0"
4-
authors = ["Francesco Cogno <francesco.cogno@outlook.com>"]
3+
version = "0.1.1"
4+
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Guido Scatena <guido.scatena@unipi.it>"]
55
description = "Prometheus Folder Size Exporter"
66
edition = "2018"
77

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Francesco Cogno
3+
Copyright (c) 2019 Francesco Cogno and 2020 Guido Scatena
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

example.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[
2-
{ "path": "/home/mindflavor", "recursive": true },
3-
{ "path": "/home/mindflavor/.cargo", "recursive": false }
2+
{ "path": "/home/mindflavor", "recursive": true, "user": "mindflavor"},
3+
{ "path": "/home/mindflavor/.cargo", "recursive": false , "user": "mindflavor"}
44
]

src/folder_scanner.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ use std::path::Path;
66
pub(crate) struct FolderToScan {
77
pub(crate) path: String,
88
pub(crate) recursive: bool,
9+
pub(crate) user: String,
910
}
1011

1112
impl FolderToScan {
1213
pub fn scan(&self) -> Result<u64, std::io::Error> {
13-
scan_folder(Path::new(&self.path), self.recursive)
14+
scan_folder(Path::new(&self.path), self.recursive, &String::from(&self.user))
1415
}
1516
}
1617

1718
#[inline]
18-
fn scan_folder(dir: &Path, is_recursive: bool) -> Result<u64, std::io::Error> {
19+
fn scan_folder(dir: &Path, is_recursive: bool, user: &String) -> Result<u64, std::io::Error> {
1920
let mut tot: u64 = 0;
2021
for entry in read_dir(dir)? {
2122
let entry = entry?;
2223
if entry.file_type()?.is_dir() && is_recursive {
23-
tot += scan_folder(&entry.path(), is_recursive)?;
24+
tot += scan_folder(&entry.path(), is_recursive, user)?;
2425
} else {
2526
tot += entry.metadata()?.len();
2627
}
@@ -74,9 +75,9 @@ mod tests {
7475
fn test_parse() {
7576
let s = "
7677
[
77-
{ \"path\": \"pippo\", \"recursive\": true },
78-
{ \"path\": \"pluto\", \"recursive\": true },
79-
{ \"path\": \"paperino\", \"recursive\": false }
78+
{ \"path\": \"pippo\", \"recursive\": true, \"user\": \"pippo\" },
79+
{ \"path\": \"pluto\", \"recursive\": true , \"user\": \"pluto\"},
80+
{ \"path\": \"paperino\", \"recursive\": false , \"user\": \"paperino\"}
8081
]
8182
";
8283

@@ -85,6 +86,7 @@ mod tests {
8586
assert_eq!(dresp.folders().len(), 3);
8687
assert_eq!(dresp.folders()[0].recursive, true);
8788
assert_eq!(dresp.folders()[2].path, "paperino");
89+
assert_eq!(dresp.folders()[2].user, "paperino");
8890
}
8991

9092
}

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ fn perform_request(
6767
let mut s = String::with_capacity(1024);
6868
for result in v_sizes {
6969
s.push_str(&format!(
70-
"folder_size{{path=\"{}\",recursive=\"{}\"}} {}\n",
71-
result.folder.path, result.folder.recursive, result.size
70+
"folder_size{{path=\"{}\",recursive=\"{}\", user=\"{}\"}} {}\n",
71+
result.folder.path, result.folder.recursive, result.folder.user, result.size
7272
));
7373
}
7474

@@ -78,8 +78,8 @@ fn perform_request(
7878

7979
fn main() {
8080
let matches = clap::App::new("prometheus_folder_size_exporter")
81-
.version("0.1")
82-
.author("Francesco Cogno <francesco.cogno@outlook.com>")
81+
.version("0.1.1")
82+
.author("Francesco Cogno <francesco.cogno@outlook.com> & Guido Scatena <guido.scatena@unipi.it>")
8383
.arg(
8484
Arg::with_name("port")
8585
.short("p")

0 commit comments

Comments
 (0)