Skip to content

Commit

Permalink
Merge branch 'eclipse-equinox:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
castortech authored Jul 1, 2022
2 parents 1d4f467 + 83317a8 commit 7f75597
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,28 +267,32 @@ protected static void convertFromProperties(EclipsePreferences node, Properties
PreferencesService.getDefault().shareStrings();
}

private final Object writeLock = new Object();

/*
* Helper method to persist a Properties object to the filesystem. We use this
* helper so we can remove the date/timestamp that Properties#store always
* puts in the file.
*/
protected static void write(Properties properties, IPath location) throws BackingStoreException {
private void write(Properties props, IPath location) throws BackingStoreException {
Path preferenceFile = location.toFile().toPath();
Path parentFile = preferenceFile.getParent();
if (parentFile == null) {
return;
}
try {
Files.createDirectories(parentFile);
String fileContent = removeTimestampFromTable(properties);
if (Files.exists(preferenceFile)) {
// Write new file content to a temporary file first to not loose the old content
// in case of a failure. If everything goes OK, it is moved to the right place.
Path tmp = preferenceFile.resolveSibling(preferenceFile.getFileName() + BACKUP_FILE_EXTENSION);
Files.writeString(tmp, fileContent, StandardCharsets.UTF_8);
Files.move(tmp, preferenceFile, StandardCopyOption.REPLACE_EXISTING);
} else {
Files.writeString(preferenceFile, fileContent, StandardCharsets.UTF_8);
String fileContent = removeTimestampFromTable(props);
synchronized (writeLock) {
if (Files.exists(preferenceFile)) {
// Write new file content to a temporary file first to not loose the old content
// in case of a failure. If everything goes OK, it is moved to the right place.
Path tmp = preferenceFile.resolveSibling(preferenceFile.getFileName() + BACKUP_FILE_EXTENSION);
Files.writeString(tmp, fileContent, StandardCharsets.UTF_8);
Files.move(tmp, preferenceFile, StandardCopyOption.REPLACE_EXISTING);
} else {
Files.writeString(preferenceFile, fileContent, StandardCharsets.UTF_8);
}
}
} catch (IOException e) {
String message = NLS.bind(PrefsMessages.preferences_saveException, location);
Expand Down

0 comments on commit 7f75597

Please sign in to comment.