Skip to main content

Plan

Struct Plan 

Source
#[non_exhaustive]
pub struct Plan { pub schema_version: SchemaVersion, pub platform: Platform, pub patches: Vec<PatchRef>, pub targets: Vec<Target>, pub fs_ops: Vec<FilesystemOp>, }
Expand description

Complete write plan for a chain of one or more source patches.

§Schema versioning

Under the serde feature, every Plan carries a schema_version: u32 that records the in-memory layout this build emits. The current value is exposed as Plan::CURRENT_SCHEMA_VERSION and is currently 1.

Compatibility policy: the schema version is bumped any time a new required field is added to Plan or any of the types it transitively contains. Additive optional fields (defaulted via #[serde(default)]) do not bump the version. On deserialize, a Plan whose persisted schema_version does not equal Plan::CURRENT_SCHEMA_VERSION is rejected with crate::IndexError::SchemaVersionMismatch — older readers refuse to silently drop fields they cannot represent, rather than risk an apply against a partial plan. Callers persisting plans across crate-version boundaries should be prepared to rebuild the plan from the patch chain on mismatch.

#[non_exhaustive]: the top-level plan owns the schema-version contract; new persisted fields land here under that contract.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§schema_version: SchemaVersion

Schema-format version of this persisted plan. See the type-level docs for the compatibility policy. New plans constructed via Plan::new / PlanBuilder always carry Plan::CURRENT_SCHEMA_VERSION.

§platform: Platform

Target platform pinned by the chain’s most recent SqpkTargetInfo chunk. Defaults to Platform::Win32 when no TargetInfo is seen.

§patches: Vec<PatchRef>

Source patches in chain order. PartSource::Patch::patch_idx indexes into this vector; the applier asks the caller’s crate::index::PatchSource for bytes by (patch_idx, offset).

§targets: Vec<Target>

Per-target write timelines, reflecting the chain’s end state — regions killed by a mid-chain RemoveAll, DeleteFile, or AddFile@0 are dropped at build time, not at apply time.

§fs_ops: Vec<FilesystemOp>

Filesystem operations to run before any region writes, in chain order. Destructive ops (DeleteFile, DeleteDir, RemoveAllInExpansion) are preserved so that the applier still removes any pre-chain artefacts that the plan’s region set does not re-create.

Implementations§

Source§

impl Plan

Source

pub const CURRENT_SCHEMA_VERSION: SchemaVersion

Current on-disk schema version for Plan under the serde feature. See the type-level docs for the compatibility policy.

Source

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

Validate that self.schema_version matches Self::CURRENT_SCHEMA_VERSION. Intended to be called by consumers immediately after deserializing a Plan from persistent storage, before handing it to the applier or verifier.

§Errors

Returns crate::IndexError::SchemaVersionMismatch when the persisted version does not equal Self::CURRENT_SCHEMA_VERSION.

Source

pub fn new( platform: Platform, patches: Vec<PatchRef>, targets: Vec<Target>, fs_ops: Vec<FilesystemOp>, ) -> Self

Construct a Plan from its component parts.

Exists so callers outside this crate can still build synthetic plans after the struct picked up #[non_exhaustive] for SemVer hygiene — in-crate code may continue to use the struct literal form directly. The constructed plan always carries Plan::CURRENT_SCHEMA_VERSION.

Source

pub fn with_crc32<S: PatchSource>(self, source: &mut S) -> Result<Self>

Consume this plan, walk every region, and return a new plan in which every applicable region’s PartExpected has been replaced with PartExpected::Crc32 of the region’s effective output bytes.

Consumes self and returns the populated plan so the mutation is honest at the type level — there’s no in-place “compute” call that silently rewrites an outwardly-immutable-looking data type. Pairs with the PlanBuilder::finish() -> Plan owned-builder style.

  • PartSource::Patch regions read the source bytes via source and, for PatchSourceKind::Deflated sources, decompress them in full before slicing the [decoded_skip..decoded_skip + region.length] window and CRC32-ing the slice. A single shared flate2::Decompress is reused across every Deflated region.
  • PartSource::Zeros regions use the canonical all-zero payload, cached per-length so plans with many same-sized Zeros regions hit crc32fast::hash once per unique length.
  • PartSource::EmptyBlock regions use the canonical empty-block payload the apply layer’s internal write_empty_block helper produces (a 20-byte SqPack empty-block header followed by units * 128 - 20 zero bytes), cached per-units.
  • PartSource::Unavailable regions are left with their existing PartExpected (typically PartExpected::SizeOnly). A single tracing::warn! summary fires per call with the total count of skipped regions — per-region tracing happens at trace!.

Once populated, crate::index::PlanVerifier uses PartExpected::Crc32 to detect single-byte damage inside Patch regions, which the v1 size-only policy missed.

§Errors

Surfaces any crate::IndexError produced by source.read or by DEFLATE decompression of a Patch region’s bytes. On error the original plan is dropped; callers that need to retry must hold an independent copy.

§Atomicity

All-or-nothing: on Ok, every applicable region in the returned plan carries a fresh PartExpected::Crc32; on Err, no partially-mutated plan is observable — the input was consumed and the staging buffer is dropped without being flushed.

Source

pub fn crc32(&self) -> u32

Stable CRC32 identity over this plan’s structural content.

Used by IndexedCheckpoint::plan_crc32 and crate::index::IndexApplier::resume_execute to detect a checkpoint that was persisted against a different plan revision than the one a resume call is given. The CRC is computed from a fixed, deterministically-ordered byte feed of every field that affects which bytes the applier writes — schema version, platform, patch chain, every target’s path and region timeline (including PartSource / PartExpected discriminants and payload), and the fs_ops list. The encoding does not match any serde format on purpose: we hash directly so the result stays stable regardless of which serializer the consumer picks for on-disk persistence.

Not cryptographic — collision space is 32 bits and the function is trivial to forge. Stale-detection only; never use this as an authentication or integrity check.

0 is a legitimate output value. CRC32 is uniform over u32 and a real plan can hash to zero; consumers must represent the “no checkpoint yet” state via Option<IndexedCheckpoint> rather than a sentinel plan_crc32: 0. See IndexedCheckpoint::plan_crc32 for the matching field doc.

Trait Implementations§

Source§

impl Clone for Plan

Source§

fn clone(&self) -> Plan

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 Plan

Source§

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

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

impl<'de> Deserialize<'de> for Plan

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 Plan

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Plan

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 Eq for Plan

Source§

impl StructuralPartialEq for Plan

Auto Trait Implementations§

§

impl Freeze for Plan

§

impl RefUnwindSafe for Plan

§

impl Send for Plan

§

impl Sync for Plan

§

impl Unpin for Plan

§

impl UnsafeUnpin for Plan

§

impl UnwindSafe for Plan

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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