prefix += "/";
}
addParentDirs(null, prefix, zOut, "", dirMode);
}
ZipFile zf = null;
try {
boolean dealingWithFiles = false;
File base = null;
if (zfs == null || zfs.getSrc(getProject()) == null) {
dealingWithFiles = true;
base = fileset.getDir(getProject());
} else {
zf = new ZipFile(zfs.getSrc(getProject()), encoding);
}
for (int i = 0; i < resources.length; i++) {
String name = null;
if (fullpath.length() > 0) {
name = fullpath;
} else {
name = resources[i].getName();
}
name = name.replace(File.separatorChar, '/');
if ("".equals(name)) {
continue;
}
if (resources[i].isDirectory() && !name.endsWith("/")) {
name = name + "/";
}
if (!doFilesonly && !dealingWithFiles
&& resources[i].isDirectory()
&& !zfs.hasDirModeBeenSet()) {
int nextToLastSlash = name.lastIndexOf("/",
name.length() - 2);
if (nextToLastSlash != -1) {
addParentDirs(base, name.substring(0,
nextToLastSlash + 1),
zOut, prefix, dirMode);
}
ZipEntry ze = zf.getEntry(resources[i].getName());
addParentDirs(base, name, zOut, prefix, ze.getUnixMode());
} else {
addParentDirs(base, name, zOut, prefix, dirMode);
}
if (!resources[i].isDirectory() && dealingWithFiles) {
File f = fileUtils.resolveFile(base,
resources[i].getName());
zipFile(f, zOut, prefix + name, fileMode);
} else if (!resources[i].isDirectory()) {
ZipEntry ze = zf.getEntry(resources[i].getName());
if (ze != null) {
boolean oldCompress = doCompress;
if (keepCompression) {
doCompress = (ze.getMethod() == ZipEntry.DEFLATED);
}
try {
zipFile(zf.getInputStream(ze), zOut, prefix + name,
ze.getTime(), zfs.getSrc(getProject()),
zfs.hasFileModeBeenSet() ? fileMode
: ze.getUnixMode());
} finally {
doCompress = oldCompress;
}
}
}
}
} finally {
if (zf != null) {
zf.close();
}
}
}