pub struct UpdateManager {
AppState: Arc<ApplicationState>,
update_status: Arc<RwLock<UpdateStatus>>,
cache_directory: PathBuf,
staging_directory: PathBuf,
backup_directory: PathBuf,
download_sessions: Arc<RwLock<HashMap<String, DownloadSession>>>,
rollback_history: Arc<Mutex<RollbackHistory>>,
update_channel: UpdateChannel,
platform_config: PlatformConfig,
}Expand description
Update manager implementation with full lifecycle support
Fields§
§AppState: Arc<ApplicationState>Application state
update_status: Arc<RwLock<UpdateStatus>>Current update status
cache_directory: PathBufUpdate cache directory
staging_directory: PathBufStaging directory for pre-installation verification
backup_directory: PathBufBackup directory for rollback capability
download_sessions: Arc<RwLock<HashMap<String, DownloadSession>>>Active download sessions with resume capability
rollback_history: Arc<Mutex<RollbackHistory>>Rollback history (max 5 versions)
update_channel: UpdateChannelUpdate channel configuration
platform_config: PlatformConfigPlatform-specific configuration
Implementations§
Source§impl UpdateManager
impl UpdateManager
Sourcepub async fn new(AppState: Arc<ApplicationState>) -> Result<Self>
pub async fn new(AppState: Arc<ApplicationState>) -> Result<Self>
Create a new update manager with comprehensive initialization
Sourcefn detect_platform() -> PlatformConfig
fn detect_platform() -> PlatformConfig
Detect the current platform and configure platform-specific settings
Sourcepub async fn CheckForUpdates(&self) -> Result<Option<UpdateInfo>>
pub async fn CheckForUpdates(&self) -> Result<Option<UpdateInfo>>
Check for available updates from the configured update server
This method:
- Queries the update server based on the configured channel
- Validates the update against minimum compatibility requirements
- Updates the internal status with available update information
- Triggers automatic download if configured
Returns: Some(UpdateInfo) if an update is available, None otherwise
Sourcepub async fn DownloadUpdate(&self, update_info: &UpdateInfo) -> Result<()>
pub async fn DownloadUpdate(&self, update_info: &UpdateInfo) -> Result<()>
Download update package with resumable download support
This method:
- Validates available disk space before starting download
- Supports resumable downloads from network interruptions
- Tracks download progress and calculates ETA
- Updates download speed metrics
- Verifies all checksums after download
§Arguments
update_info- Update information containing download URL and metadata
§Returns
Result<()> indicating success or failure
Sourcepub async fn ApplyUpdate(&self, update_info: &UpdateInfo) -> Result<()>
pub async fn ApplyUpdate(&self, update_info: &UpdateInfo) -> Result<()>
Apply update with rollback capability
This method:
- Creates full backup of current installation
- Validates update package integrity
- Applies update atomically
- Automatically rolls back on failure
- Updates rollback history
§Arguments
update_info- Update information for the version to apply
§Returns
Result<()> indicating success or failure (with automatic rollback)
Sourceasync fn FetchUpdateInfo(&self) -> Result<Option<UpdateInfo>>
async fn FetchUpdateInfo(&self) -> Result<Option<UpdateInfo>>
Fetch update information from the configured update server
This method:
- Queries the update server based on platform, version, and channel
- Uses circuit breakers and retry policies for resilience
- Returns update information if a newer version is available
§Returns
Result<Option<UpdateInfo>> - Some if update available, None if
up-to-date
Sourceasync fn VerifyChecksumWithAlgorithm(
&self,
file_path: &Path,
algorithm: &str,
expected_checksum: &str,
) -> Result<()>
async fn VerifyChecksumWithAlgorithm( &self, file_path: &Path, algorithm: &str, expected_checksum: &str, ) -> Result<()>
Verify file checksum with specified algorithm
Supports multiple checksum algorithms for comprehensive integrity checking
§Arguments
file_path- Path to the file to verifyalgorithm- Checksum algorithm (md5, sha1, sha256, sha512)expected_checksum- Expected checksum in hex format
§Returns
Result<()> indicating success or failure
Sourceasync fn VerifySignature(
&self,
_file_path: &Path,
_signature: &str,
) -> Result<()>
async fn VerifySignature( &self, _file_path: &Path, _signature: &str, ) -> Result<()>
Verify cryptographic signature of update package
This method:
- Uses Ed25519 signature verification
- Verifies the package hasn’t been tampered with
- Uses the public key configured in the system
§Arguments
file_path- Path to the signed filesignature- Base64-encoded signature
§Returns
Result<()> indicating success or failure
Sourceasync fn CreateBackup(&self, version: &str) -> Result<RollbackState>
async fn CreateBackup(&self, version: &str) -> Result<RollbackState>
Create backup of current installation
This method:
- Creates a timestamped backup directory
- Copies critical files (binaries, config, data)
- Computes checksum of backup for rollback verification
§Arguments
version- Current version being backed up
§Returns
Result<RollbackState> containing backup information
Sourcepub async fn RollbackToBackup(&self, backup_info: &RollbackState) -> Result<()>
pub async fn RollbackToBackup(&self, backup_info: &RollbackState) -> Result<()>
Sourcepub async fn RollbackToVersion(&self, version: &str) -> Result<()>
pub async fn RollbackToVersion(&self, version: &str) -> Result<()>
Sourcepub async fn GetAvailableRollbackVersions(&self) -> Vec<String>
pub async fn GetAvailableRollbackVersions(&self) -> Vec<String>
Get available rollback versions
Returns list of versions that can be rolled back to
Sourceasync fn ValidateDiskSpace(&self, required_bytes: u64) -> Result<()>
async fn ValidateDiskSpace(&self, required_bytes: u64) -> Result<()>
Sourcepub async fn verify_update(
&self,
file_path: &str,
update_info: Option<&UpdateInfo>,
) -> Result<bool>
pub async fn verify_update( &self, file_path: &str, update_info: Option<&UpdateInfo>, ) -> Result<bool>
Verify update file integrity comprehensive check
This method:
- Checks file existence and non-zero size
- Verifies all checksums if UpdateInfo provided
- Detects corrupted downloads
§Arguments
file_path- Path to the update fileupdate_info- Optional update info with checksums
§Returns
Result<bool> - true if valid, false if invalid
Sourceasync fn ApplyWindowsUpdate(&self, file_path: &Path) -> Result<()>
async fn ApplyWindowsUpdate(&self, file_path: &Path) -> Result<()>
Platform-specific update installation for Windows
Sourceasync fn ApplyMacOsUpdate(&self, file_path: &Path) -> Result<()>
async fn ApplyMacOsUpdate(&self, file_path: &Path) -> Result<()>
Platform-specific update installation for macOS
Sourceasync fn ApplyLinuxAppImageUpdate(&self, file_path: &Path) -> Result<()>
async fn ApplyLinuxAppImageUpdate(&self, file_path: &Path) -> Result<()>
Platform-specific update installation for Linux (AppImage)
Sourceasync fn ApplyLinuxDebUpdate(&self, file_path: &Path) -> Result<()>
async fn ApplyLinuxDebUpdate(&self, file_path: &Path) -> Result<()>
Platform-specific update installation for Linux (DEB)
Sourceasync fn ApplyLinuxRpmUpdate(&self, file_path: &Path) -> Result<()>
async fn ApplyLinuxRpmUpdate(&self, file_path: &Path) -> Result<()>
Platform-specific update installation for Linux (RPM)
Sourceasync fn record_telemetry(
&self,
operation: &str,
success: bool,
duration_ms: u64,
download_size: Option<u64>,
error_message: Option<String>,
)
async fn record_telemetry( &self, operation: &str, success: bool, duration_ms: u64, download_size: Option<u64>, error_message: Option<String>, )
Record telemetry for update operations
This method:
- Creates telemetry event with operation details
- In production, would send to analytics service
- Currently logs to file for debugging
§Arguments
operation- Type of operation (check, download, install, rollback)success- Whether operation succeededduration_ms- Duration in millisecondsdownload_size- Optional download size in byteserror_message- Optional error message if failed
Sourcefn CalculateSha256(&self, data: &[u8]) -> String
fn CalculateSha256(&self, data: &[u8]) -> String
Calculate SHA256 checksum of a byte slice
Sourcefn CalculateSha512(&self, data: &[u8]) -> String
fn CalculateSha512(&self, data: &[u8]) -> String
Calculate SHA512 checksum of a byte slice
Sourcefn CalculateMd5(&self, data: &[u8]) -> String
fn CalculateMd5(&self, data: &[u8]) -> String
Calculate MD5 checksum of a byte slice
Sourcefn CalculateCrc32(&self, data: &[u8]) -> String
fn CalculateCrc32(&self, data: &[u8]) -> String
Calculate CRC32 checksum of a byte slice
Sourceasync fn CalculateFileChecksum(&self, path: &Path) -> Result<String>
async fn CalculateFileChecksum(&self, path: &Path) -> Result<String>
Calculate SHA256 checksum of a file
Sourcepub fn CompareVersions(v1: &str, v2: &str) -> i32
pub fn CompareVersions(v1: &str, v2: &str) -> i32
Sourcepub async fn GetStatus(&self) -> UpdateStatus
pub async fn GetStatus(&self) -> UpdateStatus
Get current update status
Returns a clone of the current update status
Sourcepub async fn CancelDownload(&self) -> Result<()>
pub async fn CancelDownload(&self) -> Result<()>
Cancel ongoing download
This method:
- Cancels the active download session
- Cleans up temporary files
- Updates status to paused
Sourcepub async fn ResumeDownload(&self, update_info: &UpdateInfo) -> Result<()>
pub async fn ResumeDownload(&self, update_info: &UpdateInfo) -> Result<()>
Resume paused download
This method:
- Resumes a paused download session
- Uses HTTP Range header for resume capability
§Arguments
update_info- Update information to resume download
Sourcepub async fn GetUpdateChannel(&self) -> UpdateChannel
pub async fn GetUpdateChannel(&self) -> UpdateChannel
Get update configuration
Returns the current update channel configuration
Sourcepub async fn SetUpdateChannel(&mut self, channel: UpdateChannel)
pub async fn SetUpdateChannel(&mut self, channel: UpdateChannel)
Sourcepub async fn StageUpdate(&self, update_info: &UpdateInfo) -> Result<()>
pub async fn StageUpdate(&self, update_info: &UpdateInfo) -> Result<()>
Stage update for pre-installation verification
This method:
- Stages the update in the staging directory
- Verifies the staged update
- Prepares for installation
§Arguments
update_info- Update information to stage
Sourcepub async fn CleanupOldUpdates(&self) -> Result<()>
pub async fn CleanupOldUpdates(&self) -> Result<()>
Clean up old update files
Removes downloaded updates older than a certain threshold to free disk space
Sourcepub fn GetCacheDirectory(&self) -> &PathBuf
pub fn GetCacheDirectory(&self) -> &PathBuf
Get the cache directory path
Sourcepub async fn StartBackgroundTasks(&self) -> Result<JoinHandle<()>>
pub async fn StartBackgroundTasks(&self) -> Result<JoinHandle<()>>
Start background update checking task
This method:
- Periodically checks for updates based on configured interval
- Runs in a separate tokio task
- Can be cancelled by stopping the task
§Returns
Result<tokio::task::JoinHandle<()>> - Handle to the background task
Sourceasync fn BackgroundTask(&self)
async fn BackgroundTask(&self)
Background task for periodic update checks
This task:
- Checks for updates at regular intervals
- Logs any errors but doesn’t fail the task
- Can run indefinitely until stopped
Sourcepub async fn StopBackgroundTasks(&self)
pub async fn StopBackgroundTasks(&self)
Stop background tasks
This method:
- Logs the stop request
- In production, would cancel the join handle
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UpdateManager
impl !RefUnwindSafe for UpdateManager
impl Send for UpdateManager
impl Sync for UpdateManager
impl Unpin for UpdateManager
impl !UnwindSafe for UpdateManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].