Browse Source

COMPRESS-312 normalize filename in TarEntry's (File, String) constructor

master
Stefan Bodewig 10 years ago
parent
commit
71715055cd
2 changed files with 10 additions and 6 deletions
  1. +3
    -0
      WHATSNEW
  2. +7
    -6
      src/main/org/apache/tools/tar/TarEntry.java

+ 3
- 0
WHATSNEW View File

@@ -81,6 +81,9 @@ Fixed bugs:
when tasks spawned new child threads that accessed the properties.
Bugzilla Report 55074

* TarArchiveEntry's constructor with a File and a String arg didn't
normalize the name.

Other changes:
--------------



+ 7
- 6
src/main/org/apache/tools/tar/TarEntry.java View File

@@ -257,7 +257,7 @@ public class TarEntry implements TarConstants {
* @param file The file that the entry represents.
*/
public TarEntry(File file) {
this(file, normalizeFileName(file.getPath(), false));
this(file, file.getPath());
}

/**
@@ -270,6 +270,7 @@ public class TarEntry implements TarConstants {
public TarEntry(File file, String fileName) {
this();

String normalizedName = normalizeFileName(fileName, false);
this.file = file;

this.linkName = "";
@@ -278,18 +279,18 @@ public class TarEntry implements TarConstants {
this.mode = DEFAULT_DIR_MODE;
this.linkFlag = LF_DIR;

int nameLength = fileName.length();
if (nameLength == 0 || fileName.charAt(nameLength - 1) != '/') {
this.name = fileName + "/";
int nameLength = normalizedName.length();
if (nameLength == 0 || normalizedName.charAt(nameLength - 1) != '/') {
this.name = normalizedName + "/";
} else {
this.name = fileName;
this.name = normalizedName;
}
this.size = 0;
} else {
this.mode = DEFAULT_FILE_MODE;
this.linkFlag = LF_NORMAL;
this.size = file.length();
this.name = fileName;
this.name = normalizedName;
}

this.modTime = file.lastModified() / MILLIS_PER_SECOND;


Loading…
Cancel
Save