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

FELIX-6515: Add global write lock to write back cfg files #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -282,13 +282,24 @@ public void doConfigurationEvent(ConfigurationEvent configurationEvent)
{
props.remove(key);
}
try (Writer fw = new OutputStreamWriter(new FileOutputStream(file), encoding()))

// re-writing a config file must be guarded by a write lock as otherwise DirectoryWatcher
// might pick up an empty file and as a result, write this file to disk in a follow-up event
fileInstall.lock.writeLock().lockInterruptibly();
try
{
try (Writer fw = new OutputStreamWriter(new FileOutputStream(file), encoding()))
{
props.save( fw );
}
// we're just writing out what's already loaded into ConfigAdmin, so
// update file checksum since lastModified gets updated when writing
fileInstall.updateChecksum(file);
}
finally
{
props.save( fw );
fileInstall.lock.writeLock().unlock();
}
// we're just writing out what's already loaded into ConfigAdmin, so
// update file checksum since lastModified gets updated when writing
fileInstall.updateChecksum(file);
}
}
catch (Exception e)
Expand Down