Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3682 followup #3714

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions provider/adapters/src/fork/by_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where
key: DataKey,
req: DataRequest,
) -> Result<DataResponse<BufferMarker>, DataError> {
let mut last_error = DataErrorKind::MissingDataKey.with_key(key);
let mut last_error = F::UNIT_ERROR.with_key(key);
for provider in self.providers.iter() {
let result = provider.load_buffer(key, req);
match result {
Expand All @@ -193,7 +193,7 @@ where
F: ForkByErrorPredicate,
{
fn load_any(&self, key: DataKey, req: DataRequest) -> Result<AnyResponse, DataError> {
let mut last_error = DataErrorKind::MissingDataKey.with_key(key);
let mut last_error = F::UNIT_ERROR.with_key(key);
for provider in self.providers.iter() {
let result = provider.load_any(key, req);
match result {
Expand All @@ -213,7 +213,7 @@ where
F: ForkByErrorPredicate,
{
fn load_data(&self, key: DataKey, req: DataRequest) -> Result<DataResponse<M>, DataError> {
let mut last_error = DataErrorKind::MissingDataKey.with_key(key);
let mut last_error = F::UNIT_ERROR.with_key(key);
for provider in self.providers.iter() {
let result = provider.load_data(key, req);
match result {
Expand All @@ -234,7 +234,7 @@ where
F: ForkByErrorPredicate,
{
fn supported_locales_for_key(&self, key: DataKey) -> Result<Vec<DataLocale>, DataError> {
let mut last_error = F::ERROR.with_key(key);
let mut last_error = F::UNIT_ERROR.with_key(key);
for provider in self.providers.iter() {
let result = provider.supported_locales_for_key(key);
match result {
Expand All @@ -260,7 +260,7 @@ where
key: DataKey,
mut from: DataPayload<MFrom>,
) -> Result<DataPayload<MTo>, (DataPayload<MFrom>, DataError)> {
let mut last_error = F::ERROR.with_key(key);
let mut last_error = F::UNIT_ERROR.with_key(key);
for provider in self.providers.iter() {
let result = provider.convert(key, from);
match result {
Expand Down
6 changes: 3 additions & 3 deletions provider/adapters/src/fork/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use icu_provider::prelude::*;
/// [`ForkByErrorProvider`]: super::ForkByErrorProvider
pub trait ForkByErrorPredicate {
/// The error to return if there are zero providers.
const ERROR: DataErrorKind = DataErrorKind::MissingDataKey;
const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingDataKey;

/// This function is called when a data request fails and there are additional providers
/// that could possibly fulfill the request.
Expand Down Expand Up @@ -46,7 +46,7 @@ pub trait ForkByErrorPredicate {
pub struct MissingDataKeyPredicate;

impl ForkByErrorPredicate for MissingDataKeyPredicate {
const ERROR: DataErrorKind = DataErrorKind::MissingDataKey;
const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingDataKey;

#[inline]
fn test(&self, _: DataKey, _: Option<DataRequest>, err: DataError) -> bool {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl ForkByErrorPredicate for MissingDataKeyPredicate {
pub struct MissingLocalePredicate;

impl ForkByErrorPredicate for MissingLocalePredicate {
const ERROR: DataErrorKind = DataErrorKind::MissingLocale;
const UNIT_ERROR: DataErrorKind = DataErrorKind::MissingLocale;

#[inline]
fn test(&self, _: DataKey, _: Option<DataRequest>, err: DataError) -> bool {
Expand Down
8 changes: 6 additions & 2 deletions provider/fs/src/export/fs_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ impl DataExporter for FilesystemExporter {
let mut path_buf = self.root.clone().into_os_string();
write!(&mut path_buf, "/{key}").expect("infallible");

fs::create_dir_all(&path_buf)
.map_err(|e| DataError::from(e).with_path_context(&path_buf))?;
if !Path::new(&path_buf).exists() {
fs::create_dir_all(&path_buf)
.map_err(|e| DataError::from(e).with_path_context(&path_buf))?;
write!(&mut path_buf, "/.empty").expect("infallible");
fs::File::create(Path::new(&path_buf))?;
}

Ok(())
}
Expand Down