Skip to content

Commit

Permalink
Bug 1679793: Change the RLB Configuration to use PathBuf for the data…
Browse files Browse the repository at this point in the history
… path

Revert to the original format

Simplify code
  • Loading branch information
ChinYing-Li committed Feb 10, 2021
1 parent 832ccfc commit 8f1ad2a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 28 deletions.
5 changes: 3 additions & 2 deletions glean-core/rlb/examples/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::env;
use std::path::PathBuf;

use once_cell::sync::Lazy;
use tempfile::Builder;
Expand Down Expand Up @@ -36,10 +37,10 @@ fn main() {
let mut args = env::args().skip(1);

let data_path = if let Some(path) = args.next() {
path
PathBuf::from(path)
} else {
let root = Builder::new().prefix("simple-db").tempdir().unwrap();
root.path().display().to_string()
root.path().to_path_buf()
};

let cfg = Configuration {
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/src/common_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn new_glean(
clear_stores: bool,
) -> tempfile::TempDir {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = match configuration {
Some(c) => c,
Expand Down
4 changes: 3 additions & 1 deletion glean-core/rlb/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use crate::net::PingUploader;

use std::path::PathBuf;

/// The default server pings are sent to.
pub(crate) const DEFAULT_GLEAN_ENDPOINT: &str = "https://incoming.telemetry.mozilla.org";

Expand All @@ -15,7 +17,7 @@ pub struct Configuration {
/// Whether upload should be enabled.
pub upload_enabled: bool,
/// Path to a directory to store all data in.
pub data_path: String,
pub data_path: PathBuf,
/// The application ID (will be sanitized during initialization).
pub application_id: String,
/// The maximum number of events to store before sending a ping containing events.
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn initialize(cfg: Configuration, client_info: ClientInfoMetrics) {
.spawn(move || {
let core_cfg = glean_core::Configuration {
upload_enabled: cfg.upload_enabled,
data_path: cfg.data_path.clone(),
data_path: cfg.data_path.into_os_string().into_string().unwrap(),
application_id: cfg.application_id.clone(),
language_binding_name: LANGUAGE_BINDING_NAME.into(),
max_events: cfg.max_events,
Expand Down
33 changes: 16 additions & 17 deletions glean-core/rlb/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::private::PingType;
use crate::private::{BooleanMetric, CounterMetric, EventMetric};
use std::path::PathBuf;

use super::*;
use crate::common_test::{lock_test, new_glean, GLOBAL_APPLICATION_ID};
Expand Down Expand Up @@ -35,7 +34,7 @@ fn send_a_ping() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down Expand Up @@ -144,7 +143,7 @@ fn test_experiments_recording_before_glean_inits() {
set_experiment_inactive("experiment_preinit_disabled".to_string());

let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

test_reset_glean(
Configuration {
Expand Down Expand Up @@ -205,7 +204,7 @@ fn sending_of_foreground_background_pings() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down Expand Up @@ -286,7 +285,7 @@ fn sending_of_startup_baseline_ping() {
}

// Create a custom configuration to use a fake uploader.
let tmpname = data_dir.path().display().to_string();
let tmpname = data_dir.path().to_path_buf();

// Now reset Glean: it should still send a baseline ping with reason
// dirty_startup when starting, because of the dirty bit being set.
Expand Down Expand Up @@ -346,7 +345,7 @@ fn no_dirty_baseline_on_clean_shutdowns() {
}

// Create a custom configuration to use a fake uploader.
let tmpname = data_dir.path().display().to_string();
let tmpname = data_dir.path().to_path_buf();

// Now reset Glean: it should not send a baseline ping, because
// we cleared the dirty bit.
Expand Down Expand Up @@ -376,14 +375,14 @@ fn initialize_must_not_crash_if_data_dir_is_messed_up() {
let _lock = lock_test();

let dir = tempfile::tempdir().unwrap();
let tmpdirname = dir.path().display().to_string();
let tmpdirname = dir.path();
// Create a file in the temporary dir and use that as the
// name of the Glean data dir.
let file_path = PathBuf::from(tmpdirname).join("notadir");
let file_path = tmpdirname.to_path_buf().join("notadir");
std::fs::write(file_path.clone(), "test").expect("The test Glean dir file must be created");

let cfg = Configuration {
data_path: file_path.to_string_lossy().to_string(),
data_path: file_path,
application_id: GLOBAL_APPLICATION_ID.into(),
upload_enabled: true,
max_events: None,
Expand Down Expand Up @@ -442,7 +441,7 @@ fn initializing_twice_is_a_noop() {
let _lock = lock_test();

let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

test_reset_glean(
Configuration {
Expand Down Expand Up @@ -495,7 +494,7 @@ fn the_app_channel_must_be_correctly_set_if_requested() {
let _lock = lock_test();

let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

// No appChannel must be set if nothing was provided through the config
// options.
Expand Down Expand Up @@ -612,7 +611,7 @@ fn sending_deletion_ping_if_disabled_outside_of_run() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname.clone(),
Expand Down Expand Up @@ -677,7 +676,7 @@ fn no_sending_of_deletion_ping_if_unchanged_outside_of_run() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname.clone(),
Expand Down Expand Up @@ -760,7 +759,7 @@ fn setting_debug_view_tag_before_initialization_should_not_crash() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down Expand Up @@ -819,7 +818,7 @@ fn setting_source_tags_before_initialization_should_not_crash() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down Expand Up @@ -885,7 +884,7 @@ fn flipping_upload_enabled_respects_order_of_events() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down Expand Up @@ -955,7 +954,7 @@ fn registering_pings_before_init_must_work() {

// Create a custom configuration to use a fake uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/tests/init_fails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn init_fails() {

// Create a custom configuration to use a validating uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/tests/no_time_to_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn init_fails() {

// Create a custom configuration to use a validating uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/tests/overflowing_preinit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn overflowing_the_task_queue_records_telemetry() {

// Create a custom configuration to use a validating uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down
4 changes: 2 additions & 2 deletions glean-core/rlb/tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GLOBAL_APPLICATION_ID: &str = "org.mozilla.glean.test.app";
// We need to keep the `TempDir` alive, so that it's not deleted before we stop using it.
fn new_glean(configuration: Option<Configuration>) -> tempfile::TempDir {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = match configuration {
Some(c) => c,
Expand Down Expand Up @@ -74,7 +74,7 @@ fn validate_against_schema() {

// Create a custom configuration to use a validating uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down
2 changes: 1 addition & 1 deletion glean-core/rlb/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn simple_lifecycle() {

// Create a custom configuration to use a validating uploader.
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().display().to_string();
let tmpname = dir.path().to_path_buf();

let cfg = Configuration {
data_path: tmpname,
Expand Down

0 comments on commit 8f1ad2a

Please sign in to comment.