Skip to content

Commit

Permalink
Do not truncate settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Jan 7, 2025
1 parent a5ce52c commit 779f4ea
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions test/test-runner/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn read_settings_file() -> Result<String, Error> {
let mut settings_path = mullvad_paths::get_default_settings_dir()
.map_err(|error| Error::Logs(format!("{}", error)))?;
settings_path.push("settings.json");
read_truncated(&settings_path)
read_truncated(&settings_path, None)
.await
.map_err(|error| Error::Logs(format!("{}: {}", settings_path.display(), error)))
}
Expand All @@ -91,7 +91,7 @@ async fn read_log_files() -> Result<Vec<Result<LogFile, Error>>, Error> {
.map_err(|error| Error::Logs(format!("{}", error)))?;
let mut log_files = Vec::new();
for path in paths {
let log_file = read_truncated(&path)
let log_file = read_truncated(&path, Some(TRUNCATE_LOG_FILE_LINES))
.await
.map_err(|error| Error::Logs(format!("{}: {}", path.display(), error)))
.map(|content| LogFile {
Expand Down Expand Up @@ -123,17 +123,18 @@ async fn list_logs<T: AsRef<Path>>(log_dir: T) -> Result<Vec<PathBuf>, Error> {
Ok(paths)
}

async fn read_truncated<T: AsRef<Path>>(path: T) -> io::Result<String> {
async fn read_truncated<T: AsRef<Path>>(
path: T,
truncate_lines: Option<usize>,
) -> io::Result<String> {
let mut output = vec![];
let reader = BufReader::new(File::open(path).await?);
let mut lines = reader.lines();
while let Some(line) = lines.next_line().await? {
output.push(line);
}
if output.len() > TRUNCATE_LOG_FILE_LINES {
let drop_count = output.len() - TRUNCATE_LOG_FILE_LINES;
// not the most efficient
output.drain(0..drop_count);
if let Some(max_number_of_lines) = truncate_lines {
output.truncate(max_number_of_lines);
}
Ok(output.join("\n"))
}

0 comments on commit 779f4ea

Please sign in to comment.