Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issues occurring on first time password additions #3000

Merged
merged 1 commit into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void close() {
| InvalidKeySpecException
| PasswordDatabaseException
| InvalidKeyException e) {
MapTool.showError("playerDB.dialog.error.undoingChanges", e);
MapTool.showError("playerDB.dialog.error.savingChanges", e);
}
;
Players.removePropertyChangeListener(changeListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private Map<String, PlayerDetails> readPasswordFile(File file)
}
return players;
} catch (IOException ioe) {
throw new PasswordDatabaseException("msg.err.passFile.errorReadingFile", ioe);
throw new PasswordDatabaseException("msg.error.passFile.errorReadingFile", ioe);
}
} finally {
passwordFileLock.unlock();
Expand All @@ -233,7 +233,9 @@ private void writePasswordFile() throws PasswordDatabaseException {
if (dirty.compareAndSet(true, false)) {

try {
Files.copy(passwordFile.toPath(), backupPasswordFile.toPath(), REPLACE_EXISTING);
if (passwordFile.exists()) {
Files.copy(passwordFile.toPath(), backupPasswordFile.toPath(), REPLACE_EXISTING);
}
} catch (IOException ioe) {
String msg = I18N.getText("msg.err.passFile.errorCopyingBackup");
log.error(msg, ioe);
Expand Down Expand Up @@ -293,6 +295,16 @@ private void writePasswordFile() throws PasswordDatabaseException {
private void writePublicKeys(PlayerDetails playerDetails) throws IOException {
try {
passwordFileLock.lock();
File keyDir = passwordFile.getParentFile().toPath().resolve(PUBLIC_KEY_DIR).toFile();
if (!keyDir.exists()) {
keyDir.mkdirs();
}
File keyBackupDir =
passwordFile.getParentFile().toPath().resolve(PUBLIC_KEY_DIR).resolve("backup").toFile();
if (!keyBackupDir.exists()) {
keyBackupDir.mkdirs();
}

Set<PublicKeyDetails> publicKeyDetails = playerDetails.publicKeyDetails();

// First get all the public keys files with a public key marked dirty
Expand Down Expand Up @@ -550,8 +562,8 @@ public void commitChanges()
removeOldPublicKeys();
savedDetails.clear();
savedDetails.putAll(playerDetails);
dirty.set(true);
}
dirty.set(true);
writePasswordFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2546,8 +2546,7 @@ playerDB.dialog.error.passwordTooShort = Password is too short
playerDB.dialog.error.invalidPublicKey = Invalid Public Key
playerDB.dialog.error.emptyBlockReason = Blocked reason can not be empty
playerDB.dialog.error.playerExists = Player already exists
playerDB.dialog.error.undoingChanges = Error Unding database changes

playerDB.dialog.error.savingChanges = Error saving database changes
# Text to display instead of the password
playerDB.dialog.encodedPassword = -- Encoded Password --

Expand Down