Skip to content

[FELIX-6855] FileInstall prevent duplicate *.cfg files in subdirectories from corrupting live OSGi configurations - #544

Open
Jefiya-MJ wants to merge 2 commits into
apache:masterfrom
instana:upstream-fileinstall-fix
Open

[FELIX-6855] FileInstall prevent duplicate *.cfg files in subdirectories from corrupting live OSGi configurations#544
Jefiya-MJ wants to merge 2 commits into
apache:masterfrom
instana:upstream-fileinstall-fix

Conversation

@Jefiya-MJ

@Jefiya-MJ Jefiya-MJ commented Aug 13, 2026

Copy link
Copy Markdown

Problem

When felix.fileinstall.subdir.mode = recurse is active, FileInstall scans all subdirectories under the watched root and registers every matching file as an OSGi Configuration object.

Both setConfig() and deleteConfig() derive the ConfigurationAdmin PID from the filename alone via parsePid(f.getName()), discarding the directory path entirely. This means any two files with the same name —
regardless of where they sit in the directory tree — resolve to the same PID.

Consequences:

  • If a file with the same name as a live configuration is copied into a subdirectory, setConfig() overwrites the live configuration's felix.fileinstall.filename property with the duplicate file's URI, silently stealing ownership.

  • When the duplicate file is later deleted, deleteConfig() resolves the same PID and calls config.delete() on the live Configuration object — removing it from ConfigurationAdmin even though the original physical file was never touched. Dependent OSGi services stop immediately and cannot restart.

Fix

Before acting on a resolved Configuration object, both setConfig()and deleteConfig() now compare the absolute URI of the file under operation against the felix.fileinstall.filename property already stored in that Configuration.

String registeredFileName = (String) props.get(DirectoryWatcher.FILENAME);
if (registeredFileName != null && !registeredFileName.equals(toConfigKey(f))) {
    return false;
}

Reproduction Scenario

  1. Configure felix.fileinstall.subdir.mode = recurse (default).
  2. Let FileInstall register /watched/etc/app.cfg as PID app.
  3. Copy /watched/etc/app.cfg to /watched/backup/etc/app.cfg.
  4. Delete /watched/backup/etc/app.cfg.
  5. Before this patch: deleteConfig() resolves PID app and removes the live configuration from ConfigurationAdmin. The service stops.
  6. After this patch: deleteConfig() detects the URI mismatch and returns false without touching ConfigurationAdmin.

@Jefiya-MJ Jefiya-MJ changed the title [FILEINSTALL] Prevent duplicate *.cfg files in subdirectories from corrupting live OSGi configurations [FELIX-6855] FileInstall prevent duplicate *.cfg files in subdirectories from corrupting live OSGi configurations Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant