Browse Source

getting close to Info-Zip now, will enable it next week

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273617 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
6c7ff01478
3 changed files with 50 additions and 2 deletions
  1. +30
    -0
      src/main/org/apache/tools/zip/ZipEntry.java
  2. +1
    -1
      src/main/org/apache/tools/zip/ZipOutputStream.java
  3. +19
    -1
      src/testcases/org/apache/tools/zip/ZipEntryTest.java

+ 30
- 0
src/main/org/apache/tools/zip/ZipEntry.java View File

@@ -68,7 +68,11 @@ import java.util.zip.ZipException;
*/
public class ZipEntry extends java.util.zip.ZipEntry {

private static final int PLATFORM_UNIX = 3;
private static final int PLATFORM_FAT = 0;

private int internalAttributes = 0;
private int platform = PLATFORM_FAT;
private long externalAttributes = 0;
private Vector extraFields = new Vector();

@@ -186,6 +190,32 @@ public class ZipEntry extends java.util.zip.ZipEntry {
externalAttributes = value;
}

/**
* Sets Unix permissions in a way that is understood by Info-Zip's
* unzip command.
*
* @since Ant 1.6
*/
public void setUnixMode(int mode) {
setExternalAttributes((mode << 16)
// MS-DOS directory flag
| (isDirectory() ? 0x10 : 0));
platform = PLATFORM_UNIX;
}

/**
* Platform specification to put into the &quot;version made
* by&quot; part of the central file header.
*
* @return 0 (MS-DOS FAT) unless {@link #setUnixMode setUnixMode}
* has been called, in which case 3 (Unix) will be returned.
*
* @since Ant 1.6
*/
public int getPlatform() {
return platform;
}

/**
* Replaces all currently attached extra fields with the new array.
*


+ 1
- 1
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -519,7 +519,7 @@ public class ZipOutputStream extends DeflaterOutputStream {
written += 4;

// version made by
out.write((new ZipShort(20)).getBytes());
out.write((new ZipShort((ze.getPlatform() << 8) | 20)).getBytes());
written += 2;

// version needed to extract


+ 19
- 1
src/testcases/org/apache/tools/zip/ZipEntryTest.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -121,4 +121,22 @@ public class ZipEntryTest extends TestCase {
} catch (java.util.NoSuchElementException nse) {
}
}

public void testUnixMode() {
ZipEntry ze = new ZipEntry("foo");
assertEquals(0, ze.getPlatform());
ze.setUnixMode(0755);
assertEquals(3, ze.getPlatform());
assertEquals(0755,
(ze.getExternalAttributes() >> 16) & 0xFFFF);
assertEquals(0, ze.getExternalAttributes() & 0xFFFF);

ze = new ZipEntry("foo/");
ze.setUnixMode(0577);
assertEquals(3, ze.getPlatform());
assertEquals(0577,
(ze.getExternalAttributes() >> 16) & 0xFFFF);
assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF);
}

}

Loading…
Cancel
Save