MCPcopy Index your code
hub / github.com/celer-pkg/celer / removeSystemGroupAndUser

Function removeSystemGroupAndUser

pkgcache/cache_setup.go:523–562  ·  view source on GitHub ↗
(username string)

Source from the content-addressed store, hash-verified

521}
522
523func removeSystemGroupAndUser(username string) error {
524 // If the user is still in the group, groupdel may fail or leave the system in an inconsistent state.
525 if err := removeCurrentUserFromGroup(username); err != nil {
526 return err
527 }
528
529 // Remove system user.
530 userExists := true
531 if _, err := lookupUser(username); err != nil {
532 var unknownUserError user.UnknownUserError
533 if !errors.As(err, &unknownUserError) {
534 return fmt.Errorf("failed to lookup %s user -> %w", username, err)
535 }
536 userExists = false
537 }
538 if userExists {
539 if output, err := cmd.NewExecutor("", "userdel", username).ExecuteOutput(); err != nil {
540 return fmt.Errorf("failed to remove %s user -> %s -> %w", username, output, err)
541 }
542 color.PrintHint("✔ remove system user %s", username)
543 }
544
545 // Remove system group.
546 groupExists := true
547 if _, err := lookupGroup(username); err != nil {
548 var unknownGroupError user.UnknownGroupError
549 if !errors.As(err, &unknownGroupError) {
550 return fmt.Errorf("failed to lookup %s group -> %w", username, err)
551 }
552 groupExists = false
553 }
554 if groupExists {
555 if output, err := cmd.NewExecutor("", "groupdel", username).ExecuteOutput(); err != nil {
556 return fmt.Errorf("failed to remove %s group -> %s -> %w", username, output, err)
557 }
558 color.PrintHint("✔ remove system group: %s", username)
559 }
560
561 return nil
562}
563
564func removeCurrentUserFromGroup(groupName string) error {
565 currentUser, err := currentUserForGroup()

Callers 2

RemoveMethod · 0.85
RemoveMethod · 0.85

Calls 4

NewExecutorFunction · 0.92
PrintHintFunction · 0.92
ExecuteOutputMethod · 0.80

Tested by

no test coverage detected