Skip to content

Commit

Permalink
Merge pull request ow2-proactive#3196 from fviale/master
Browse files Browse the repository at this point in the history
Fix for ow2-proactive#3195 DataSpace Client does not preserve directory hierarchy when transferring single file
  • Loading branch information
fviale authored Apr 26, 2018
2 parents 5f09180 + 42cd5aa commit cb8f043
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.zip.*;

import org.apache.log4j.Logger;
import org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector;

import com.google.common.base.Predicate;
Expand All @@ -45,6 +46,8 @@

public class Zipper {

private static final Logger logger = Logger.getLogger(Zipper.class);

private static byte[] MAGIC = { 'P', 'K', 0x3, 0x4 };

private Zipper() {
Expand Down Expand Up @@ -123,17 +126,10 @@ private static void zipFiles(List<File> files, String basepath, OutputStream os)
try {
ZipOutputStream zos = new ZipOutputStream(os);
closer.register(zos);
if (files.size() == 1) {
File file = files.get(0);
for (File file : files) {
FileInputStream inputStream = new FileInputStream(file);
closer.register(inputStream);
writeZipEntry(new ZipEntry(file.getName()), inputStream, zos);
} else {
for (File file : files) {
FileInputStream inputStream = new FileInputStream(file);
closer.register(inputStream);
writeZipEntry(zipEntry(basepath, file), inputStream, zos);
}
writeZipEntry(zipEntry(basepath, file), inputStream, zos);
}
} catch (IOException ioe) {
throw closer.rethrow(ioe);
Expand All @@ -146,6 +142,7 @@ public static void writeZipEntry(ZipEntry zipEntry, InputStream is, ZipOutputStr
Closer closer = Closer.create();
closer.register(is);
try {
logger.trace("Adding zip entry" + zipEntry.toString());
zos.putNextEntry(zipEntry);
ByteStreams.copy(is, zos);
zos.flush();
Expand Down Expand Up @@ -259,7 +256,13 @@ public boolean apply(File file) {

FileSelector selector = new FileSelector(includes, excludes);

return !file.isDirectory() && selector.matches(pathRelativeToRoot);
boolean answer = !file.isDirectory() && selector.matches(pathRelativeToRoot);
if (logger.isTraceEnabled()) {
logger.trace("Analysing file " + file + " for selector " + selector + " : " + answer);
logger.trace("Path relative to root : " + pathRelativeToRoot);
}

return answer;
}

}
Expand Down
Loading

0 comments on commit cb8f043

Please sign in to comment.