Skip to content

Commit 70baf7a

Browse files
authored
Merge pull request #18 from openobserve/fix/dir-permission
fix: permission of data directory
2 parents 764b067 + d4fc01f commit 70baf7a

File tree

10 files changed

+296
-155
lines changed

10 files changed

+296
-155
lines changed

Cargo.lock

Lines changed: 60 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "o2_report_generator"
3-
version = "0.1.0"
3+
version = "0.11.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -13,6 +13,13 @@ chromiumoxide = { git = "https://github.com/mattsse/chromiumoxide", features = [
1313
"_fetcher-rusttls-tokio",
1414
], default-features = false, rev = "6f2392f78ae851e2acf33df8e9764cc299d837db" }
1515
chrono = { version = "0.4", default-features = false, features = ["clock"] }
16+
clap = { version = "4.5", default-features = false, features = [
17+
"std",
18+
"help",
19+
"usage",
20+
"suggestions",
21+
"cargo",
22+
] }
1623
dotenv_config = "0.1"
1724
dotenvy = "0.15"
1825
env_logger = "0.10"

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ FROM public.ecr.aws/debian/debian:bookworm-slim as runtime
44
RUN apt-get update -y && apt-get install -y --no-install-recommends ca-certificates chromium && \
55
update-ca-certificates
66
COPY ./bin/report-generator /
7+
RUN ["/report-generator", "init-dir", "-p", "/data/"]
78
CMD ["/report-generator"]

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-07-07"
2+
channel = "nightly-2025-03-02"
33
components = ["rustfmt", "clippy", "llvm-tools"]

src/cli/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 OpenObserve Inc.
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU Affero General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Affero General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
mod utils;
17+
18+
pub async fn cli() -> Result<bool, anyhow::Error> {
19+
let app = clap::Command::new("report-generator")
20+
.version(crate::config::VERSION)
21+
.about(clap::crate_description!())
22+
.subcommands(&[clap::Command::new("init-dir")
23+
.about("init report-generator data dir")
24+
.arg(
25+
clap::Arg::new("path")
26+
.short('p')
27+
.long("path")
28+
.help("init this path as data root dir"),
29+
)])
30+
.get_matches();
31+
32+
if app.subcommand().is_none() {
33+
return Ok(false);
34+
}
35+
36+
let (name, command) = app.subcommand().unwrap();
37+
if name == "init-dir" {
38+
match command.get_one::<String>("path") {
39+
Some(path) => {
40+
utils::set_permission(path, 0o777)?;
41+
println!("init dir {} successfully", path);
42+
}
43+
None => {
44+
return Err(anyhow::anyhow!("please set data path"));
45+
}
46+
}
47+
return Ok(true);
48+
}
49+
50+
println!("command {name} execute successfully");
51+
Ok(true)
52+
}

src/cli/utils.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 OpenObserve Inc.
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU Affero General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Affero General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
#[cfg(unix)]
17+
pub fn set_permission<P: AsRef<std::path::Path>>(path: P, mode: u32) -> Result<(), std::io::Error> {
18+
use std::os::unix::fs::PermissionsExt;
19+
std::fs::create_dir_all(path.as_ref())?;
20+
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(mode))
21+
}
22+
23+
#[cfg(not(unix))]
24+
pub fn set_permission<P: AsRef<std::path::Path>>(
25+
path: P,
26+
_mode: u32,
27+
) -> Result<(), std::io::Error> {
28+
std::fs::create_dir_all(path.as_ref())
29+
}

0 commit comments

Comments
 (0)