pub struct LifecycleTaskControl<'runner> { /* private fields */ }Expand description
Registering, reading and removing the product’s lifecycle task.
Everything goes through a CommandRunner, so the whole of this — the
argument vectors, the idempotent replacement, the foreign-task refusal and
the non-destructive removal — is testable on a CI leg that has no Task
Scheduler at all.
Implementations§
Source§impl<'runner> LifecycleTaskControl<'runner>
impl<'runner> LifecycleTaskControl<'runner>
Sourcepub fn new(runner: &'runner dyn CommandRunner) -> Self
pub fn new(runner: &'runner dyn CommandRunner) -> Self
Uses the host’s schtasks.exe.
Sourcepub fn with_executable(
runner: &'runner dyn CommandRunner,
schtasks: impl Into<PathBuf>,
) -> Self
pub fn with_executable( runner: &'runner dyn CommandRunner, schtasks: impl Into<PathBuf>, ) -> Self
Uses a named schtasks.exe, for a test.
Sourcepub fn query(
&self,
identity: &LifecycleTaskIdentity,
) -> Result<Option<RegisteredTask>, WslError>
pub fn query( &self, identity: &LifecycleTaskIdentity, ) -> Result<Option<RegisteredTask>, WslError>
What Task Scheduler holds under this name, if anything.
§Errors
WslError::Spawn when schtasks.exe cannot be started at all.
Sourcepub fn register(&self, task: &LifecycleTask) -> Result<(), WslError>
pub fn register(&self, task: &LifecycleTask) -> Result<(), WslError>
Registers the task, replacing a previous registration of the same task.
Idempotent: running it twice leaves one task whose definition is the
current one. schtasks /Create … /F is what makes the replacement
atomic from Task Scheduler’s point of view — there is no window in
which the task is absent.
§Errors
WslError::ForeignTask when a task of this name exists and is not
this product’s, or exists but cannot be exported and so cannot be shown
to be this product’s; WslError::TaskControl when schtasks refused;
WslError::Record when the document could not be written to a
temporary file for schtasks /XML to read.
Sourcepub fn detach(
&self,
identity: &LifecycleTaskIdentity,
) -> Result<Detached, WslError>
pub fn detach( &self, identity: &LifecycleTaskIdentity, ) -> Result<Detached, WslError>
Removes the product’s task, and nothing else.
This is the whole of wsl detach’s Windows half. It does not
unregister the WSL distribution, stop or uninstall the Linux service,
remove a credential, or delete any Linux data — it cannot, because the
only program it runs is schtasks.exe.
§Errors
WslError::ForeignTask when the task is not this product’s, and
WslError::TaskControl when schtasks refused to delete it.
Sourcepub fn start(&self, identity: &LifecycleTaskIdentity) -> Result<(), WslError>
pub fn start(&self, identity: &LifecycleTaskIdentity) -> Result<(), WslError>
Starts the task now, rather than at the next logon.
§Errors
WslError::NoSuchTask when nothing is registered,
WslError::ForeignTask when the registration is not this product’s,
and WslError::TaskControl when schtasks refused.