[
https://issues.apache.org/jira/browse/COMPRESS-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15101757#comment-15101757
]
Torsten Curdt commented on COMPRESS-328:
----------------------------------------
{quote}
maybe add a new constructor that sets the flag but doesn't require the name at
the same time.
{quote}
Now you got me confused - so you are suggesting adding a flag AND adding a
parameter to {{setName}}?
{quote}
I don't think any of the other archivers uses a normalization similar to tar.
{quote}
Why does only the {{TarArchiver}} do it then? Why was it introduced?
Talking code I see the following 3 options (in order of size of change of
behaviour):
1)
{code}
public void setName(String name) {
this.name = normalizeFileName(name, false);
}
public void setName(String name, boolean preserveLeadingSlashes) {
this.name = normalizeFileName(name, preserveLeadingSlashes);
}
{code}
2)
{code}
public TarArchiveEntry(String name, boolean preserveLeadingSlashes) {
this();
this.preserverLeadingSlashes = preserveLeadingSlashes;
name = normalizeFileName(name, preserveLeadingSlashes);
boolean isDir = name.endsWith("/");
this.name = name;
this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE;
this.linkFlag = isDir ? LF_DIR : LF_NORMAL;
this.modTime = new Date().getTime() / MILLIS_PER_SECOND;
this.userName = "";
}
public TarArchiveEntry(String name) {
this();
boolean isDir = name.endsWith("/");
this.name = name;
this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE;
this.linkFlag = isDir ? LF_DIR : LF_NORMAL;
this.modTime = new Date().getTime() / MILLIS_PER_SECOND;
this.userName = "";
}
public void setName(String name) {
this.name = normalizeFileName(name, this.preserveLeadingSlashes);
}
{code}
3)
{code}
@deprecated
public TarArchiveEntry(String name, boolean preserveLeadingSlashes) {
this();
name = normalizeFileName(name, preserveLeadingSlashes);
boolean isDir = name.endsWith("/");
this.name = name;
this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE;
this.linkFlag = isDir ? LF_DIR : LF_NORMAL;
this.modTime = new Date().getTime() / MILLIS_PER_SECOND;
this.userName = "";
}
public TarArchiveEntry(String name) {
this();
boolean isDir = name.endsWith("/");
this.name = name;
this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE;
this.linkFlag = isDir ? LF_DIR : LF_NORMAL;
this.modTime = new Date().getTime() / MILLIS_PER_SECOND;
this.userName = "";
}
public void setName(String name) {
this.name = name;
}
{code}
I am leaning towards 2) as it is a minor behavioural change - but I find 3) the
most clean (given that other Archivers do not normalize). 1) I am not a fan
because it accumulates technical debt.
The question is whether we can get away with announcing the behaviour change in
a 1.x release. (I would be all for it)
I guess 3) would probably need to be in a major release.
> TarArchiveEntry preserveLeadingSlashes has no effect on setName
> ---------------------------------------------------------------
>
> Key: COMPRESS-328
> URL: https://issues.apache.org/jira/browse/COMPRESS-328
> Project: Commons Compress
> Issue Type: Improvement
> Reporter: Torsten Curdt
> Priority: Minor
>
> We've run into an inconsistency with the TarArchiveEntry at jdeb.
> https://github.com/tcurdt/jdeb/issues/217
> You can create a `TarArchiveEntry(String name, boolean
> preserveLeadingSlashes)` but the `preserveLeadingSlashes` is only applied in
> the constructor.
> https://github.com/apache/commons-compress/blob/master/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java#L392
> I am proposing to turn `preserveLeadingSlashes` into a read-only property and
> use the value on `setName()`, too (instead of just false).
> This has some implications and maybe some backwards compatibility issues -
> but even then I think it would be the right thing to do.
> I am happy to make the change but thought to discuss this first.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)