jkevan opened a new pull request, #562:
URL: https://github.com/apache/felix-dev/pull/562

   Fixes [FELIX-6862](https://issues.apache.org/jira/browse/FELIX-6862).
   
   ## What happens
   
   `ConfigInstaller` adopts every configuration that records 
`felix.fileinstall.filename`, whatever the format of the file. The `CM_DELETED` 
path then deletes the file that the resulting `pidToFile` entry names. An 
installer therefore deletes a configuration file that another 
`ArtifactInstaller` handles.
   
   ## Why
   
   [FELIX-5832](https://issues.apache.org/jira/browse/FELIX-5832) added a 
`canHandle` filter to the `CM_UPDATED` path in 2018, under the rule its subject 
states: only handle `ConfigurationEvent` objects managed by us. Three sites 
read or write `pidToFile`, and that change covered one of them.
   
   - `init()` puts every configuration that records a file name into 
`pidToFile`, with no filter.
   - The `CM_DELETED` path removes the pid from `pidToFile` and deletes the 
file, with no filter.
   
   The defect needs a restart, because `init()` is the only unfiltered writer 
of `pidToFile`. The guarded `CM_UPDATED` path rejects a foreign format, so a 
configuration created while the container runs never enters the map.
   
   ## What changed
   
   `init()` applies the filter, so a file of another format no longer enters 
`pidToFile`. The `CM_DELETED` path applies it too, because deleting the file is 
the act that loses data. A filter at each writer alone makes the invariant 
depend on every future writer repeating it.
   
   `init()` passes `new File(fileName)` rather than `fromConfigKey(fileName)`. 
`canHandle` reads the file name only, and `fromConfigKey` calls `URI.create`, 
which throws on a value that is not a URI. The catch around that loop would 
then leave `pidToFile` half-built.
   
   Behaviour for `.cfg` and `.config` files is unchanged.
   
   ## Tests
   
   - `testCmDeletedKeepsAFileOfAnotherInstallersFormat` creates a `.yml` file, 
runs `init()`, raises `CM_DELETED`, and asserts the file survives. The test 
fails when both filters are removed.
   - `testCmDeletedStillRemovesAFileOfItsOwnFormat` does the same with a `.cfg` 
file and asserts the file is deleted. The result is the same with and without 
the filters, so the test guards the unchanged path.
   
   The first test pins the behaviour rather than each filter, because either 
filter delivers the behaviour on its own and `pidToFile` is private. The 
comment at each filter states why that filter is there.
   
   `mvn test` on the `fileinstall` module passes on JDK 11, except 
`DirectoryWatcherTest.testInvalidTempDir`. That test also fails on an 
unmodified `master` on this machine, which is 
[FELIX-6837](https://issues.apache.org/jira/browse/FELIX-6837).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to