commit 8959d90e280f438fcec16a344ef227317a299c3a Author: Karsten Loesing karsten.loesing@gmx.net Date: Tue Apr 17 17:30:05 2012 +0200
Improve reading descriptors from tarballs. --- src/org/torproject/descriptor/DescriptorFile.java | 14 ++++++++++++-- .../descriptor/impl/DescriptorFileImpl.java | 16 ++++++++++++++++ .../descriptor/impl/DescriptorReaderImpl.java | 12 +++++++----- 3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/src/org/torproject/descriptor/DescriptorFile.java b/src/org/torproject/descriptor/DescriptorFile.java index 863ce92..153b700 100644 --- a/src/org/torproject/descriptor/DescriptorFile.java +++ b/src/org/torproject/descriptor/DescriptorFile.java @@ -9,12 +9,22 @@ import java.util.List; * descriptors. */ public interface DescriptorFile {
- /* Return the directory where this descriptor file was contained. */ + /* Return the directory where this descriptor file was contained, or + * null if the file was contained in a tarball. */ public File getDirectory();
- /* Return the descriptor file itself. */ + /* Return the tarball where this descriptor file was contained, or null + * if the file was not contained in a tarball. */ + public File getTarball(); + + /* Return the descriptor file itself, or null if the descriptor file was + * contained in a tarball. */ public File getFile();
+ /* Return the descriptor file name, which is either the absolute path of + * the file on disk, or the tar file entry name. */ + public String getFileName(); + /* Return the time in millis when the descriptor file on disk was last * modified. */ public long getLastModified(); diff --git a/src/org/torproject/descriptor/impl/DescriptorFileImpl.java b/src/org/torproject/descriptor/impl/DescriptorFileImpl.java index 787961b..7ab9a24 100644 --- a/src/org/torproject/descriptor/impl/DescriptorFileImpl.java +++ b/src/org/torproject/descriptor/impl/DescriptorFileImpl.java @@ -19,6 +19,14 @@ public class DescriptorFileImpl implements DescriptorFile { return this.directory; }
+ private File tarball; + protected void setTarball(File tarball) { + this.tarball = tarball; + } + public File getTarball() { + return this.tarball; + } + private File file; protected void setFile(File file) { this.file = file; @@ -27,6 +35,14 @@ public class DescriptorFileImpl implements DescriptorFile { return this.file; }
+ private String fileName; + protected void setFileName(String fileName) { + this.fileName = fileName; + } + public String getFileName() { + return this.fileName; + } + private long lastModified; protected void setLastModified(long lastModified) { this.lastModified = lastModified; diff --git a/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java index 7db883b..d5f779d 100644 --- a/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java +++ b/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java @@ -221,13 +221,15 @@ public class DescriptorReaderImpl implements DescriptorReader { BufferedInputStream bis = new BufferedInputStream(tais); TarArchiveEntry tae = null; while ((tae = tais.getNextTarEntry()) != null) { + if (tae.isDirectory()) { + continue; + } DescriptorFileImpl descriptorFile = new DescriptorFileImpl(); - /* TODO Is it correct to set these values for files - * contained in a tarball? */ - descriptorFile.setDirectory(tarball); - descriptorFile.setFile(null); - descriptorFile.setLastModified(lastModifiedMillis); + descriptorFile.setTarball(tarball); + descriptorFile.setFileName(tae.getName()); + descriptorFile.setLastModified(tae.getLastModifiedDate(). + getTime()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len; byte[] data = new byte[1024];