MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SaveUser

Function SaveUser

internal/users/users.go:612–659  ·  view source on GitHub ↗
(u UserRecord, isAutoSave ...bool)

Source from the content-addressed store, hash-verified

610}
611
612func SaveUser(u UserRecord, isAutoSave ...bool) error {
613
614 fileWritten := false
615 tmpSaved := false
616 tmpCopied := false
617 completed := false
618
619 defer func() {
620 mudlog.Info("SaveUser()", "username", u.Username, "wrote-file", fileWritten, "tmp-file", tmpSaved, "tmp-copied", tmpCopied, "completed", completed)
621 }()
622
623 data, err := yaml.Marshal(&u)
624 if err != nil {
625 return err
626 }
627
628 carefulSave := configs.GetFilePathsConfig().CarefulSaveFiles
629
630 path := util.FilePath(string(configs.GetFilePathsConfig().DataFiles), `/`, `users`, `/`, strconv.Itoa(u.UserId)+`.yaml`)
631
632 saveFilePath := path
633 if carefulSave { // careful save first saves a {filename}.new file
634 saveFilePath += `.new`
635 }
636
637 err = util.WriteFile(saveFilePath, data, 0600)
638 if err != nil {
639 return err
640 }
641 fileWritten = true
642 if carefulSave {
643 tmpSaved = true
644 }
645
646 if carefulSave {
647 //
648 // Once the file is written, rename it to remove the .new suffix and overwrite the old file
649 //
650 if err := os.Rename(saveFilePath, path); err != nil {
651 return err
652 }
653 tmpCopied = true
654 }
655
656 completed = true
657
658 return nil
659}
660
661func GetUniqueUserId() int {
662

Callers 15

swapToAltFunction · 0.92
characterCommandMethod · 0.92
apiV1PutUserPermissionsFunction · 0.92
apiV1PatchUserFunction · 0.92
HandleLeaveFunction · 0.92
visit_SetUnsetFunction · 0.92
PasswordFunction · 0.92
SaveFunction · 0.92
ModifyFunction · 0.92
mainFunction · 0.92
SaveAllUsersFunction · 0.85

Calls 5

InfoFunction · 0.92
GetFilePathsConfigFunction · 0.92
FilePathFunction · 0.92
WriteFileFunction · 0.92
RenameMethod · 0.45

Tested by 1