[
https://issues.apache.org/jira/browse/SLING-13440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ankur Singla updated SLING-13440:
---------------------------------
Description:
SLING-12837 fixed the writeback of configurations whose node name carries a
legacy extension
(e.g. {{jcrinstall:/path/to/config.config}} was written back as
{{{}/path/to/config.config.cfg.json{}}}).
However, the fix does not handle nodes {*}without any extension{*}. Nodes of
type {{sling:OsgiConfig}}
named with just the PID are a supported format (see [JCR Installer
docs|https://sling.apache.org/documentation/bundles/jcr-installer-provider.html],
e.g. {{{}/apps/jcrtest/install/some.config.pid{}}}).
h3. Problem
In {{{}JcrInstaller.handleUpdate(){}}}, the "ensure extension" branch now
strips everything after the last dot (.) of the node name and appends
{{{}.cfg.json{}}}:
{code:java}
final int lastDot = nodePath.lastIndexOf('.');
final int lastSlash = nodePath.lastIndexOf('/');
if (lastDot <= lastSlash) {
path = oldPath + CONFIG_FILE_EXTENSION;
} else {
path = oldPath.substring(0, lastDot) + CONFIG_FILE_EXTENSION;
}
{code}
Since OSGi PIDs are dotted, the last PID segment is treated as an extension and
removed.
h3. Steps to reproduce
# Create a node {{/apps/myapp/config/org.example.impl.MyService}} of type
{{sling:OsgiConfig}} with some properties.
# Let the JCR installer install it.
# Update the configuration via Configuration Admin (e.g. Web Console),
triggering the installer writeback.
*Expected:* configuration is written back to
{{/apps/myapp/config/org.example.impl.MyService.cfg.json}} (PID
{{{}org.example.impl.MyService{}}}).
*Actual:* configuration is written to
{{{}/apps/myapp/config/org.example.impl.cfg.json{}}}, i.e. PID
{{{}org.example.impl{}}}.
The original PID is effectively lost and a lower-priority configuration for
that PID (if any) becomes active.
Additionally, {{lastDot}} is computed on {{nodePath}} but applied to
{{{}oldPath{}}}; the two can differ when
{{getPathWithHighestPrio()}} re-roots the path, which may produce wrong paths
or an index error.
h3. Proposed fix
Strip only known configuration extensions instead of the substring after the
last dot, and use
{{nodePath}} consistently:
{code:java}
String base = nodePath;
for (final String ext : new String[] {".cfg.json", ".config", ".cfg"}) {
if (base.endsWith(ext)) {
base = base.substring(0, base.length() - ext.length());
break;
}
}
path = base + CONFIG_FILE_EXTENSION;
{code}
was:
SLING-12837 fixed the writeback of configurations whose node name carries a
legacy extension
(e.g. {{jcrinstall:/path/to/config.config}} was written back as
{{{}/path/to/config.config.cfg.json{}}}).
However, the fix does not handle nodes {*}without any extension{*}. Nodes of
type {{sling:OsgiConfig}}
named with just the PID are a supported format (see [JCR Installer
docs|https://sling.apache.org/documentation/bundles/jcr-installer-provider.html],
e.g. {{{}/apps/jcrtest/install/some.config.pid{}}}).
h3. Problem
In {{{}JcrInstaller.handleUpdate(){}}}, the "ensure extension" branch now
strips everything after the last dot (.) of the node name and appends
{{{}.cfg.json{}}}:
{code:java}
final int lastDot = nodePath.lastIndexOf('.');
final int lastSlash = nodePath.lastIndexOf('/');
if (lastDot <= lastSlash) {
path = oldPath + CONFIG_FILE_EXTENSION;
} else {
path = oldPath.substring(0, lastDot) + CONFIG_FILE_EXTENSION;
}
{code}
Since OSGi PIDs are dotted, the last PID segment is treated as an extension and
removed.
h3. Steps to reproduce
# Create a node {{/apps/myapp/config/org.example.impl.MyService}} of type
{{sling:OsgiConfig}} with some properties.
# Let the JCR installer install it.
# Update the configuration via Configuration Admin (e.g. Web Console),
triggering the installer writeback.
*Expected:* configuration is written back to
{{/apps/myapp/config/org.example.impl.MyService.cfg.json}} (PID
{{{}org.example.impl.MyService{}}}).
*Actual:* configuration is written to
{{{}/apps/myapp/config/org.example.impl.cfg.json{}}}, i.e. PID
{{{}org.example.impl{}}}.
The original PID is effectively lost and a lower-priority configuration for
that PID (if any) becomes active.
Additionally, {{lastDot}} is computed on {{nodePath}} but applied to
{{{}oldPath{}}}; the two can differ when
{{getPathWithHighestPrio()}} re-roots the path, which may produce wrong paths
or an index error.
h3. Proposed fix
Strip only known configuration extensions instead of the substring after the
last dot, and use
{{nodePath}} consistently:
{code:java}
String base = nodePath;
for (final String ext : new String[] {".cfg.json", ".config", ".cfg"}) {
if (base.endsWith(ext)) {
base = base.substring(0, base.length() - ext.length());
break;
}
}
path = base + CONFIG_FILE_EXTENSION;
{code}
Unit tests to cover: bare singleton PID, factory PID ({{{}~{}}} and {{-}}
separators), {{{}.config{}}}, {{{}.cfg{}}},
{{{}.cfg.json{}}}, and a node outside the highest-priority root.
> JCR installer truncates PID when writing back a sling:OsgiConfig node without
> file extension
> --------------------------------------------------------------------------------------------
>
> Key: SLING-13440
> URL: https://issues.apache.org/jira/browse/SLING-13440
> Project: Sling
> Issue Type: Bug
> Components: Installer
> Reporter: Ankur Singla
> Priority: Major
> Fix For: JCR Installer 3.3.2
>
>
> SLING-12837 fixed the writeback of configurations whose node name carries a
> legacy extension
> (e.g. {{jcrinstall:/path/to/config.config}} was written back as
> {{{}/path/to/config.config.cfg.json{}}}).
> However, the fix does not handle nodes {*}without any extension{*}. Nodes of
> type {{sling:OsgiConfig}}
> named with just the PID are a supported format (see [JCR Installer
> docs|https://sling.apache.org/documentation/bundles/jcr-installer-provider.html],
> e.g. {{{}/apps/jcrtest/install/some.config.pid{}}}).
> h3. Problem
> In {{{}JcrInstaller.handleUpdate(){}}}, the "ensure extension" branch now
> strips everything after the last dot (.) of the node name and appends
> {{{}.cfg.json{}}}:
> {code:java}
> final int lastDot = nodePath.lastIndexOf('.');
> final int lastSlash = nodePath.lastIndexOf('/');
> if (lastDot <= lastSlash) {
> path = oldPath + CONFIG_FILE_EXTENSION;
> } else {
> path = oldPath.substring(0, lastDot) + CONFIG_FILE_EXTENSION;
> }
> {code}
> Since OSGi PIDs are dotted, the last PID segment is treated as an extension
> and removed.
> h3. Steps to reproduce
> # Create a node {{/apps/myapp/config/org.example.impl.MyService}} of type
> {{sling:OsgiConfig}} with some properties.
> # Let the JCR installer install it.
> # Update the configuration via Configuration Admin (e.g. Web Console),
> triggering the installer writeback.
> *Expected:* configuration is written back to
> {{/apps/myapp/config/org.example.impl.MyService.cfg.json}} (PID
> {{{}org.example.impl.MyService{}}}).
> *Actual:* configuration is written to
> {{{}/apps/myapp/config/org.example.impl.cfg.json{}}}, i.e. PID
> {{{}org.example.impl{}}}.
> The original PID is effectively lost and a lower-priority configuration for
> that PID (if any) becomes active.
> Additionally, {{lastDot}} is computed on {{nodePath}} but applied to
> {{{}oldPath{}}}; the two can differ when
> {{getPathWithHighestPrio()}} re-roots the path, which may produce wrong paths
> or an index error.
> h3. Proposed fix
> Strip only known configuration extensions instead of the substring after the
> last dot, and use
> {{nodePath}} consistently:
> {code:java}
> String base = nodePath;
> for (final String ext : new String[] {".cfg.json", ".config", ".cfg"}) {
> if (base.endsWith(ext)) {
> base = base.substring(0, base.length() - ext.length());
> break;
> }
> }
> path = base + CONFIG_FILE_EXTENSION;
> {code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)