Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 35 additions & 10 deletions device-detection-onpremise/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use fiftyone_pipeline_engines::{
};

use crate::engine::{open_manager, DeviceDetectionOnPremiseEngine};
use crate::operational_copy::OperationalCopy;

/// The download type the Distributor serves Hash data files as, sent in the
/// update URL's `Type` parameter.
Expand Down Expand Up @@ -72,6 +73,7 @@ pub struct DeviceDetectionOnPremiseEngineBuilder {
data_source_tier: Option<String>,
auto_update: Option<AutoUpdate>,
concurrency: Option<u16>,
temp_dir: Option<PathBuf>,
}

/// The optional automatic-update settings captured by the builder.
Expand All @@ -95,6 +97,7 @@ impl DeviceDetectionOnPremiseEngineBuilder {
data_source_tier: None,
auto_update: None,
concurrency: None,
temp_dir: None,
}
}

Expand All @@ -119,6 +122,15 @@ impl DeviceDetectionOnPremiseEngineBuilder {
self
}

/// Set the folder for the engine's temporary files. With automatic updates
/// on, every profile but [`PerformanceProfile::InMemory`] reads a copy of
/// the data file made there, so an update can replace the data file itself.
/// Defaults to the system's temporary folder, [`std::env::temp_dir`].
pub fn temp_dir_path(mut self, path: impl Into<PathBuf>) -> Self {
self.temp_dir = Some(path.into());
self
}

/// Restrict the engine to a single named property, adding to any already
/// requested. With no restriction the engine loads every property the data
/// file supports.
Expand Down Expand Up @@ -219,22 +231,35 @@ impl DeviceDetectionOnPremiseEngineBuilder {
};
data_file_config.check_license_keys()?;

// Open the data set with the requested property restriction.
let manager = open_manager(
// Open the data set with the requested property restriction, from a
// copy of the data file when updates can replace the file while it is
// open.
let copy = OperationalCopy::when_needed(
&self.data_file_path,
self.temp_dir.as_deref(),
self.profile,
&data_file_config,
);
let manager = open_manager(
copy.as_ref()
.map_or(self.data_file_path.as_path(), OperationalCopy::path),
self.profile,
&self.requested_properties,
self.concurrency,
)?;

let engine = Arc::new(DeviceDetectionOnPremiseEngine::from_manager(
manager,
self.profile,
self.requested_properties,
data_file_config,
self.data_source_tier,
self.concurrency,
));
let engine = Arc::new(
DeviceDetectionOnPremiseEngine::from_manager(
manager,
copy,
self.profile,
self.requested_properties,
data_file_config,
self.data_source_tier,
self.concurrency,
)
.with_temp_dir(self.temp_dir),
);

// Register the data file with the update service if one was supplied.
if let Some(service) = service {
Expand Down
Loading
Loading