pub async fn change_user_name(
context: &Context<'_>,
current_name: &str,
new_name: &str,
) -> Result<()>Expand description
Renames a user account.
Like Linux usermod --login without --move-home, renaming keeps the
recorded home: alice renamed to alicia keeps /users/alice, and its
contents are neither moved nor lost. Because that home stays recorded, the
name alice cannot be given to a new account: create_user refuses it
with UserHomeAlreadyUsed.
The record file is moved to its new name before the registry is updated.
If the registry update fails, the function attempts to move the file back.
After a successful update, the function replaces the record’s contents
atomically. This saves the new name and upgrades version 0 records to
version 1 with their /users/<identifier> home. That rewrite is
best effort: the record’s file name is authoritative, so if it fails, or
power is lost before it, the account still loads under its new name. A
failed rewrite is logged and the rename still succeeds.
§Errors
InvalidUserName- The new name does not satisfy [users::is_valid_user_name]FailedToRenameUser- The new name is already used, or the account is not registered- File system errors (reading, moving, writing user file)
- JSON parsing errors