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

refactor(autonomi): deterministic archive #2599

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 4 additions & 7 deletions autonomi/src/client/files/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use std::{
collections::HashMap,
collections::BTreeMap,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -36,8 +36,6 @@ pub enum RenameError {
/// Metadata for a file in an archive. Time values are UNIX timestamps.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Metadata {
/// When the file was (last) uploaded to the network.
pub uploaded: u64,
/// File creation time on local file system. See [`std::fs::Metadata::created`] for details per OS.
pub created: u64,
/// Last file modification time taken from local file system. See [`std::fs::Metadata::modified`] for details per OS.
Expand All @@ -55,7 +53,6 @@ impl Metadata {
.as_secs();

Self {
uploaded: now,
created: now,
modified: now,
size,
Expand All @@ -68,15 +65,15 @@ impl Metadata {
/// The data maps are stored within this structure instead of uploading them to the network, keeping the data private.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PrivateArchive {
map: HashMap<PathBuf, (DataMapChunk, Metadata)>,
map: BTreeMap<PathBuf, (DataMapChunk, Metadata)>,
}

impl PrivateArchive {
/// Create a new emtpy local archive
/// Note that this does not upload the archive to the network
pub fn new() -> Self {
Self {
map: HashMap::new(),
map: BTreeMap::new(),
}
}

Expand Down Expand Up @@ -130,7 +127,7 @@ impl PrivateArchive {
}

/// Get the underlying map
pub fn map(&self) -> &HashMap<PathBuf, (DataMapChunk, Metadata)> {
pub fn map(&self) -> &BTreeMap<PathBuf, (DataMapChunk, Metadata)> {
&self.map
}

Expand Down
8 changes: 4 additions & 4 deletions autonomi/src/client/files/archive_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use std::{
collections::HashMap,
collections::BTreeMap,
path::{Path, PathBuf},
};

Expand All @@ -34,15 +34,15 @@ pub type ArchiveAddr = XorName;
/// to the network, of which the addresses are stored in this archive.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PublicArchive {
map: HashMap<PathBuf, (DataAddr, Metadata)>,
map: BTreeMap<PathBuf, (DataAddr, Metadata)>,
}

impl PublicArchive {
/// Create a new emtpy local archive
/// Note that this does not upload the archive to the network
pub fn new() -> Self {
Self {
map: HashMap::new(),
map: BTreeMap::new(),
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl PublicArchive {
}

/// Get the underlying map
pub fn map(&self) -> &HashMap<PathBuf, (DataAddr, Metadata)> {
pub fn map(&self) -> &BTreeMap<PathBuf, (DataAddr, Metadata)> {
&self.map
}

Expand Down
5 changes: 0 additions & 5 deletions autonomi/src/client/files/fs_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub(crate) fn metadata_from_entry(entry: &walkdir::DirEntry) -> Metadata {
entry.path().display()
);
return Metadata {
uploaded: 0,
created: 0,
modified: 0,
size: 0,
Expand Down Expand Up @@ -224,10 +223,6 @@ pub(crate) fn metadata_from_entry(entry: &walkdir::DirEntry) -> Metadata {
let modified = unix_time("modified", fs_metadata.modified());

Metadata {
uploaded: SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or(Duration::from_secs(0))
.as_secs(),
created,
modified,
size: fs_metadata.len(),
Expand Down
Loading