Skip to main content

Registry

Struct Registry 

Source
pub struct Registry {
    pub version: String,
    pub settings: Settings,
    pub repositories: HashMap<PathBuf, RepoEntry>,
    pub total_freed_bytes: u64,
    pub total_pruned_count: u64,
    pub last_added_repos: Vec<PathBuf>,
    pub last_prune: Option<LastPrune>,
    pub prune_history: Vec<PruneRunSummary>,
    pub last_update_check: Option<DateTime<Utc>>,
    pub latest_known_version: Option<String>,
    pub restore_rates: BTreeMap<String, RestoreRate>,
}
Expand description

The top-level registry structure persisted to disk.

Fields§

§version: String

Schema version for forward compatibility.

§settings: Settings

Global settings.

§repositories: HashMap<PathBuf, RepoEntry>

Map of canonical repo paths to their metadata.

§total_freed_bytes: u64

Total cumulative bytes freed historically across all prune passes.

§total_pruned_count: u64

How many prune passes have deleted something, ever.

One per pass, not per repository and not per directory — a devp run that cleared eleven directories across four repositories counts once. Incremented in exactly one place, Registry::record_prune, which is also where the pass is recorded for devp restore --last-run; keeping the two together is what stops them meaning different things depending on which command did the pruning.

§last_added_repos: Vec<PathBuf>

List of repository paths added in the most recent init/link action (for devp undo).

§last_prune: Option<LastPrune>

What the most recent prune pass deleted (for devp restore --last-run).

§prune_history: Vec<PruneRunSummary>

Summaries of recent prune passes, oldest first, for devp stats.

Capped at constants::PRUNE_HISTORY_LIMIT. Recorded from 1.1.0 onward.

§last_update_check: Option<DateTime<Utc>>

When the release check last ran, so it runs at most once every UPDATE_CHECK_INTERVAL_DAYS instead of on every command.

§latest_known_version: Option<String>

The newest release seen by the last check, so the reminder survives until the user actually upgrades without needing the network again.

§restore_rates: BTreeMap<String, RestoreRate>

How fast each adapter has actually restored on this machine.

Measured by devp restore --last-run, which is the one command that knows both how long a restore took and how many bytes it put back. Local only: nothing here is uploaded, compared against anyone else’s machine, or used for anything except the estimate devp status prints. See docs/PRIVACY.md.

Implementations§

Source§

impl Registry

Source

pub fn config_dir() -> Result<PathBuf>

Returns the path to the config directory (~/.config/dev-prune/).

Uses the dirs crate to resolve the platform-specific config location:

  • Linux/macOS: ~/.config/dev-prune/
  • Windows: C:\Users\<user>\AppData\Roaming\dev-prune\ (or ~/.config/dev-prune/)
Source

pub fn registry_path() -> Result<PathBuf>

Returns the full path to the registry file.

Source

pub fn load() -> Result<Self>

Loads the registry from disk, or the defaults when there is nothing to load.

Reading does not write. This used to persist the default registry on the way out, which made devp --dry-run init create the very file it had just promised not to write and gave devp status --json — documented as a pure read — a side effect on first use. Every command that actually changes something calls Registry::save, and that creates the directory as needed.

Source

pub fn load_from(path: &Path) -> Result<Self>

Loads the registry from a specific path (for testing or custom locations).

Non-persisting, exactly like Registry::load, which is implemented on top of it. The two used to disagree — this one wrote the defaults out when the file was missing — which is the sort of difference that makes a test pass while the behaviour it stands in for is broken.

Source

pub fn save(&self) -> Result<()>

Saves the registry to disk atomically (write to temp, then rename).

Source

pub fn save_to(&self, path: &Path) -> Result<()>

Saves the registry to a specific path (for testing or custom locations).

Source

pub fn add_repo(&mut self, path: PathBuf) -> bool

Adds a repository to the registry. Returns true if newly added, false if already present.

Source

pub fn adopt_moved_entry( &mut self, path: &Path, identity: Option<String>, ) -> Adoption

Record identity against a registered repository, and hand it the history of the entry it moved away from.

Called after add_repo from both link and init. When exactly one registered path no longer exists on disk and carries the same root commit, that entry is the same repository at its old location: its added_at, prune history and settings move across and the dead row is removed. Two dead entries claiming one identity is a clone, not a move, so nothing is guessed — the caller says so instead.

Also the backfill path. Entries registered before 1.4.0 have no identity, so nothing they do can be recognised as a move; re-registering them records one, and a single devp init ~/code backfills the whole registry.

Source

pub fn needs_identity(&self, path: &Path) -> bool

Whether a registered repository still has no recorded identity.

The global Git hook runs devp link --quiet on every commit, and backfilling unconditionally would shell out to git and rewrite the registry once per commit forever. This makes it once per repository.

Source

pub fn remove_repo(&mut self, path: &Path) -> bool

Removes a repository from the registry. Returns true if it was present.

A repository that has been deleted from disk cannot be canonicalised any more, so canonical_key falls back to the path as typed — which never equals the canonical key it was registered under (on Windows those carry the \\?\ prefix). Unlinking a deleted repository is the most ordinary reason to unlink at all, so a direct miss falls back to a lexical comparison.

Source

pub fn mark_pruned(&mut self, path: &Path, bytes_freed: u64)

Credit bytes_freed to one repository, and to the machine-wide total.

Safe to call once per repository or once per directory — every figure it touches is either a sum or a timestamp, so the two styles agree. Counting passes is deliberately not done here for exactly that reason; that lives in Registry::record_prune, which is called once per pass.

Source

pub fn record_restore(&mut self, adapter: &str, bytes: u64, millis: u64)

Record what a prune pass deleted, replacing any earlier record.

A pass that deleted nothing is not a pass worth remembering, so an empty list is ignored rather than stored — otherwise devp run on an already-clean machine would quietly throw away the record of the run the user actually wants back.

This is the one place a prune pass is counted. It sets Registry::last_prune, appends a PruneRunSummary to Registry::prune_history and bumps Registry::total_pruned_count, because “a pass happened and it deleted things” is exactly the condition all three describe. Splitting them across call sites is how the counter previously came to mean repositories in devp run and directories in the devp status dashboard. Fold one measured restore into an adapter’s running average.

Ignores anything too quick to have been real work — see constants::RESTORE_RATE_MIN_MILLIS — because a manager that found everything still in its cache returns in a moment and would teach a throughput no cold restore can reach. That is the difference between an estimate that is optimistic and one that is wrong.

Source

pub fn estimate_restore( &self, by_adapter: &[(String, u64)], ) -> Option<(f64, u64)>

How long putting back by_adapter would take, from what this machine has measured.

Returns the seconds and the bytes those seconds account for. Anything from an adapter that has never been timed here is left out of both, so a caller can say how much of the estimate is actually covered rather than quietly quoting a number for half the work. None when nothing is covered at all — an estimate with no measurement behind it is a guess, and this command does not print guesses.

Source

pub fn record_prune(&mut self, dirs: Vec<PrunedDir>)

Source

pub fn record_prune_progress(&mut self, at: DateTime<Utc>, dirs: Vec<PrunedDir>)

Record a pass’s progress mid-flight, superseding this same pass’s earlier record.

at identifies the pass: a repeated call with the same timestamp replaces the history entry and last_prune it wrote before, rather than counting a second pass. This exists so a long pass can persist after every repository — a crash half-way through used to leave devp restore --last-run pointing at the previous pass, offering to reinstall directories that were never deleted while saying nothing about the ones that were.

Source

pub fn repo_count(&self) -> usize

Returns the number of registered repositories.

Trait Implementations§

Source§

impl Clone for Registry

Source§

fn clone(&self) -> Registry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Registry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Registry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Registry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Registry

Source§

fn eq(&self, other: &Registry) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Registry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Registry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.