Skip to content

Finishing TODO in pingora-header-serde for checking if path is a file + avoiding panics #925

Description

@omavashia2005

In

pub fn train<P: AsRef<std::path::Path>>(dir_path: P) -> Vec<u8> {
// TODO: check f is file, it can be dir
let files = fs::read_dir(dir_path)
.unwrap()
.filter_map(|entry| entry.ok().map(|f| f.path()));
dict::from_files(files, 64 * 1024 * 1024).unwrap()
}

The TODO can be easily completed and the return type can be changed to Result<Vec<u8>, Error> to account for invalid paths (and avoid panics on unwrap).

I will be making a PR soon after this issue is published - I made the minimum required changes and all the tests in the same file pass with cargo test from the subdirectory and cargo test -p pingora-header-serde from root.

Thanks!

Om

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions