-
Notifications
You must be signed in to change notification settings - Fork 164
[FELIX-6855] FileInstall prevent duplicate *.cfg files in subdirectories from corrupting live OSGi configurations #544
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,6 +388,17 @@ boolean setConfig(final File f) throws Exception | |
| clearReadOnlyIfWritable(pid, config, f); | ||
|
|
||
| Dictionary<String, Object> props = config.getProperties(); | ||
|
|
||
| // Only update if this file is the registered source of the configuration, | ||
| // or if no source has been registered yet (new configuration). | ||
| // Skips duplicate files that share the same PID but originate from a different path. | ||
| if (props != null) { | ||
| String registeredFileName = (String) props.get(DirectoryWatcher.FILENAME); | ||
| if (registeredFileName != null && !registeredFileName.equals(toConfigKey(f))) { | ||
| return false; | ||
| } | ||
| } | ||
|
Comment on lines
+396
to
+400
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The skip is permanent and never retried, so a legitimate file move detected across two scan cycles loses the configuration for good.
Scenario (
Before this patch the config survived step 2 (re-created from the surviving file on the next change). Same root cause produces a permanently orphaned Consider recording rejected paths and re-evaluating them when the owning configuration disappears ( |
||
|
|
||
| Hashtable<String, Object> old = props != null ? new Hashtable<String, Object>(new DictionaryAsMap<>(props)) : null; | ||
| if (old != null) { | ||
| old.remove( DirectoryWatcher.FILENAME ); | ||
|
|
@@ -433,6 +444,17 @@ boolean deleteConfig(File f) throws Exception | |
| { | ||
| String pid[] = parsePid(f.getName()); | ||
| Configuration config = getConfiguration(toConfigKey(f), pid[0], pid[1]); | ||
|
|
||
| // Only delete if this file is the registered source of the configuration. | ||
| // If the registered felix.fileinstall.filename does not match the file being deleted, skip deletion to protect the live config. | ||
| Dictionary<String, Object> props = config.getProperties(); | ||
| if (props != null) { | ||
| String registeredFileName = (String) props.get(DirectoryWatcher.FILENAME); | ||
| if (registeredFileName != null && !registeredFileName.equals(toConfigKey(f))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing the two URIs as raw strings instead of as file identities makes the guard fire on paths that denote the same file.
Scenario: an admin initially sets Comparing resolved files rather than strings avoids this: String registeredFileName = (String) props.get(DirectoryWatcher.FILENAME);
if (registeredFileName != null
&& !fromConfigKey(registeredFileName).getAbsoluteFile().equals(f.getAbsoluteFile())) {
return false;
}( |
||
| return false; | ||
| } | ||
| } | ||
|
Comment on lines
+454
to
+456
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent skip: this is the only exit from Every other outcome in Also, the javadoc above still reads |
||
|
|
||
| Util.log(context, Logger.LOG_INFO, "Deleting configuration {" | ||
| + config.getPid() | ||
| + "} from " + f.getAbsolutePath(), null); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
| testkey=testvalue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early return sits after
clearReadOnlyIfWritable()but before thetry/finallythat callssetReadOnlyInNotWritable(), so it leaks the READ_ONLY attribute of the live configuration.Scenario:
/watched/etc/app.cfgis read-only, so the live configuration for PIDappcarries the READ_ONLY attribute. A writable duplicate/watched/backup/app.cfgis then dropped into a subdirectory.clearReadOnlyIfWritable(pid, config, f)(line 388) seesUtil.canWrite(duplicate) == trueand strips READ_ONLY from the live config. The new check then returnsfalse, so thefinally { setReadOnlyInNotWritable(...) }block is never reached and the attribute is never restored. The live configuration is left permanently writable — exactly the kind of cross-file interference this PR sets out to prevent.The check needs to run before
clearReadOnlyIfWritable: