FileBasedConfig: ensure correct snapshot if no file
When no config file exists, use FileSnapshot.MISSING_FILE. Bug: 451508 Change-Id: I8a09cb756a8a4746189da5b3514dfcf81d10b3b1 Signed-off-by: Thomas Wolf <twolf@apache.org>
This commit is contained in:
parent
621685d3ca
commit
cb46ee3544
|
@ -117,13 +117,11 @@ boolean exists() {
|
||||||
@Override
|
@Override
|
||||||
public void load() throws IOException, ConfigInvalidException {
|
public void load() throws IOException, ConfigInvalidException {
|
||||||
try {
|
try {
|
||||||
FileSnapshot[] lastSnapshot = { null };
|
|
||||||
Boolean wasRead = FileUtils.readWithRetries(getFile(), f -> {
|
Boolean wasRead = FileUtils.readWithRetries(getFile(), f -> {
|
||||||
final FileSnapshot oldSnapshot = snapshot;
|
final FileSnapshot oldSnapshot = snapshot;
|
||||||
final FileSnapshot newSnapshot;
|
final FileSnapshot newSnapshot;
|
||||||
// don't use config in this snapshot to avoid endless recursion
|
// don't use config in this snapshot to avoid endless recursion
|
||||||
newSnapshot = FileSnapshot.saveNoConfig(f);
|
newSnapshot = FileSnapshot.saveNoConfig(f);
|
||||||
lastSnapshot[0] = newSnapshot;
|
|
||||||
final byte[] in = IO.readFully(f);
|
final byte[] in = IO.readFully(f);
|
||||||
final ObjectId newHash = hash(in);
|
final ObjectId newHash = hash(in);
|
||||||
if (hash.equals(newHash)) {
|
if (hash.equals(newHash)) {
|
||||||
|
@ -149,7 +147,7 @@ public void load() throws IOException, ConfigInvalidException {
|
||||||
});
|
});
|
||||||
if (wasRead == null) {
|
if (wasRead == null) {
|
||||||
clear();
|
clear();
|
||||||
snapshot = lastSnapshot[0];
|
snapshot = FileSnapshot.MISSING_FILE;
|
||||||
}
|
}
|
||||||
exists.set(wasRead != null);
|
exists.set(wasRead != null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue