Remove Repository::initialize
This patch removes the method `Repository::initialize`, which
was only really used by `FileSystemRepository`. This was done
because it removes the risk of creating an uninitialized
repository. Instead, initialization can be guaranteed by
performing initialization on the `Repository` creation.
diff --git a/src/client.rs b/src/client.rs
index b9933c0..145ccae 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -28,7 +28,8 @@
//! .map(|k| KeyId::from_string(k).unwrap())
//! .collect();
//!
-//! let local = FileSystemRepository::<Json>::new(PathBuf::from("~/.rustup"));
+//! let local = FileSystemRepository::<Json>::new(PathBuf::from("~/.rustup"))
+//! .unwrap();
//!
//! let remote = HttpRepository::new(
//! Url::parse("https://static.rust-lang.org/").unwrap(),
@@ -131,10 +132,7 @@
///
/// **WARNING**: This method offers weaker security guarantees than the related method
/// `with_root_pinned`.
- pub fn new(config: Config<T>, mut local: L, mut remote: R) -> Result<Self> {
- local.initialize()?;
- remote.initialize()?;
-
+ pub fn new(config: Config<T>, mut local: L, remote: R) -> Result<Self> {
let root = local
.fetch_metadata(
&Role::Root,
@@ -179,9 +177,6 @@
I: IntoIterator<Item = &'a KeyId>,
T: PathTranslator,
{
- local.initialize()?;
- remote.initialize()?;
-
let root = local
.fetch_metadata(
&Role::Root,
diff --git a/src/repository.rs b/src/repository.rs
index e0d36a8..3059e61 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -28,9 +28,6 @@
/// The type returned when reading a target.
type TargetRead: Read;
- /// Initialize the repository.
- fn initialize(&mut self) -> Result<()>;
-
/// Store signed metadata.
///
/// Note: This **MUST** canonicalize the bytes before storing them as a read will expect the
@@ -108,11 +105,17 @@
D: DataInterchange,
{
/// Create a new repository on the local file system.
- pub fn new(local_path: PathBuf) -> Self {
- FileSystemRepository {
+ pub fn new(local_path: PathBuf) -> Result<Self> {
+ for p in &["metadata", "targets", "temp"] {
+ DirBuilder::new().recursive(true).create(
+ local_path.join(p),
+ )?
+ }
+
+ Ok(FileSystemRepository {
local_path,
interchange: PhantomData,
- }
+ })
}
}
@@ -122,16 +125,6 @@
{
type TargetRead = File;
- fn initialize(&mut self) -> Result<()> {
- for p in &["metadata", "targets", "temp"] {
- DirBuilder::new().recursive(true).create(
- self.local_path.join(p),
- )?
- }
-
- Ok(())
- }
-
fn store_metadata<M>(
&mut self,
role: &Role,
@@ -331,10 +324,6 @@
{
type TargetRead = Response;
- fn initialize(&mut self) -> Result<()> {
- Ok(())
- }
-
/// This always returns `Err` as storing over HTTP is not yet supported.
fn store_metadata<M>(
&mut self,
@@ -446,10 +435,6 @@
{
type TargetRead = Cursor<Vec<u8>>;
- fn initialize(&mut self) -> Result<()> {
- Ok(())
- }
-
fn store_metadata<M>(
&mut self,
role: &Role,
@@ -540,7 +525,6 @@
#[test]
fn ephemeral_repo_targets() {
let mut repo = EphemeralRepository::<Json>::new();
- repo.initialize().unwrap();
let data: &[u8] = b"like tears in the rain";
let target_description = TargetDescription::from_reader(data, &[HashAlgorithm::Sha256])
@@ -562,8 +546,7 @@
#[test]
fn file_system_repo_targets() {
let temp_dir = TempDir::new("rust-tuf").unwrap();
- let mut repo = FileSystemRepository::<Json>::new(temp_dir.path().to_path_buf());
- repo.initialize().unwrap();
+ let mut repo = FileSystemRepository::<Json>::new(temp_dir.path().to_path_buf()).unwrap();
// test that init worked
assert!(temp_dir.path().join("metadata").exists());