UserEnvironment.preSudo constructor

UserEnvironment.preSudo({
  1. required String pathToHome,
})

Creates a UserEnvironment from the SUDO env args that describe the pre-sudo user.

Implementation

UserEnvironment.preSudo({required this.pathToHome}) {
  // get the details of the user, pre-sudo starting.
  final sUID = env['SUDO_UID'];
  final gUID = env['SUDO_GID'];

  // convert id's to integers.
  gid = gUID != null ? int.tryParse(gUID) ?? 0 : 0;
  uid = sUID != null ? int.tryParse(sUID) ?? 0 : 0;

  // CONSIDER: throw an exception if we can't determine the opre-sudo
  // user?
  username = env['SUDO_USER'] ?? env['USER'] ?? '';

  pathToShell = env['SHELL'];
}