summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2015-06-12 15:45:25 +0200
committerBenoit Lamarche <benoitlamarche@google.com>2015-06-17 18:26:04 +0200
commitf01db511461651a993ae2f33a9c9b19a7c1fe515 (patch)
tree33d5e43b59f5d0b87b52d0a8479d798cfe8eb656
parent325b47a0195f7ee1a711f87bee42c8293523f558 (diff)
downloadtoolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.zip
toolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.tar.gz
toolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.tar.bz2
Add support for case-sensitive FS in ReadWriteZipFS
Also: - deleted ZipInputOutputVFSCodec which is unused and similar to ZipFSCodec. - introduce constants in JackLibrary for numGroups and groupSize. Bug: 21796981 (cherry picked from commit 37f4d45c334a2e15f0d8aee2fadb2cd823b4ee54) Change-Id: Id744da9c97a04adf728b8688c91a0816715d5cce
-rw-r--r--jack/src/com/android/jack/library/InputJackLibraryCodec.java3
-rw-r--r--jack/src/com/android/jack/library/JackLibrary.java4
-rw-r--r--sched/src/com/android/sched/util/codec/ZipFSCodec.java10
-rw-r--r--sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java72
-rw-r--r--sched/src/com/android/sched/vfs/CaseInsensitiveFS.java17
-rw-r--r--sched/src/com/android/sched/vfs/ReadWriteZipFS.java15
-rw-r--r--sched/tests/com/android/sched/vfs/VFSTest.java31
7 files changed, 57 insertions, 95 deletions
diff --git a/jack/src/com/android/jack/library/InputJackLibraryCodec.java b/jack/src/com/android/jack/library/InputJackLibraryCodec.java
index 4dbc3f9..f8ba636 100644
--- a/jack/src/com/android/jack/library/InputJackLibraryCodec.java
+++ b/jack/src/com/android/jack/library/InputJackLibraryCodec.java
@@ -87,7 +87,8 @@ public class InputJackLibraryCodec implements StringCodec<InputJackLibrary> {
ChangePermission.NOCHANGE), Permission.READ | Permission.WRITE);
try {
Service service = messageDigestCodec.checkString(context, "SHA");
- vfs = new CaseInsensitiveFS(directFS, /* nbGroup = */ 1, /* szGroup = */ 2,
+ vfs = new CaseInsensitiveFS(directFS, /* numGroups = */ JackLibrary.NUM_GROUPS_FOR_DIRS,
+ /* groupSize = */ JackLibrary.GROUP_SIZE_FOR_DIRS,
new MessageDigestFactory(service), /* debug = */ false);
} catch (WrongVFSFormatException e) {
vfs = directFS;
diff --git a/jack/src/com/android/jack/library/JackLibrary.java b/jack/src/com/android/jack/library/JackLibrary.java
index 3f98f4d..d91b66b 100644
--- a/jack/src/com/android/jack/library/JackLibrary.java
+++ b/jack/src/com/android/jack/library/JackLibrary.java
@@ -44,6 +44,10 @@ public interface JackLibrary extends Library {
@Nonnull
public static final String KEY_LIB_EMITTER_VERSION = "lib.emitter.version";
+ public static final int GROUP_SIZE_FOR_DIRS = 2;
+
+ public static final int NUM_GROUPS_FOR_DIRS = 1;
+
@Nonnull
public String getProperty(@Nonnull String key) throws LibraryFormatException;
diff --git a/sched/src/com/android/sched/util/codec/ZipFSCodec.java b/sched/src/com/android/sched/util/codec/ZipFSCodec.java
index 4cc8bce..835a9f1 100644
--- a/sched/src/com/android/sched/util/codec/ZipFSCodec.java
+++ b/sched/src/com/android/sched/util/codec/ZipFSCodec.java
@@ -19,6 +19,7 @@ package com.android.sched.util.codec;
import com.android.sched.util.RunnableHooks;
import com.android.sched.util.config.ConfigurationError;
+import com.android.sched.util.config.MessageDigestFactory;
import com.android.sched.util.file.FileOrDirectory.ChangePermission;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.FileOrDirectory.Permission;
@@ -27,6 +28,7 @@ import com.android.sched.vfs.ReadWriteZipFS;
import com.android.sched.vfs.VFS;
import java.io.IOException;
+import java.security.Provider.Service;
import javax.annotation.Nonnull;
@@ -36,6 +38,9 @@ import javax.annotation.Nonnull;
*/
public class ZipFSCodec extends FileOrDirCodec<VFS> {
+ @Nonnull
+ private final MessageDigestCodec messageDigestCodec = new MessageDigestCodec();
+
public ZipFSCodec(@Nonnull Existence existence) {
super(existence, Permission.READ | Permission.WRITE);
}
@@ -92,8 +97,11 @@ public class ZipFSCodec extends FileOrDirCodec<VFS> {
@Nonnull final String string) throws ParsingException {
RunnableHooks hooks = context.getRunnableHooks();
try {
+ Service service = messageDigestCodec.checkString(context, "SHA");
return new ReadWriteZipFS(
- new OutputZipFile(context.getWorkingDirectory(), string, hooks, existence, change));
+ new OutputZipFile(context.getWorkingDirectory(), string, hooks, existence, change),
+ /* numGroups = */ 1, /* groupSize = */ 2,
+ new MessageDigestFactory(service), /* debug = */ false);
} catch (IOException e) {
throw new ParsingException(e.getMessage(), e);
}
diff --git a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java
deleted file mode 100644
index 6c6da20..0000000
--- a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.util.codec;
-
-
-import com.android.sched.util.RunnableHooks;
-import com.android.sched.util.file.FileOrDirectory.Existence;
-import com.android.sched.util.file.OutputZipFile;
-import com.android.sched.util.log.LoggerFactory;
-import com.android.sched.vfs.GenericInputOutputVFS;
-import com.android.sched.vfs.InputOutputVFS;
-import com.android.sched.vfs.ReadWriteZipFS;
-
-import java.io.IOException;
-import java.util.logging.Logger;
-
-import javax.annotation.Nonnull;
-
-/**
- * This {@link StringCodec} is used to create an instance of {@link InputOutputVFS} backed by a
- * filesystem directory, which is then zipped when closed.
- */
-public class ZipInputOutputVFSCodec extends InputOutputVFSCodec
- implements StringCodec<InputOutputVFS> {
-
- @Nonnull
- private final Logger logger = LoggerFactory.getLogger();
-
- public ZipInputOutputVFSCodec(@Nonnull Existence existence) {
- super(existence);
- }
-
- @Override
- @Nonnull
- public String getUsage() {
- return "a path to a zip archive (" + getUsageDetails() + ")";
- }
-
- @Override
- @Nonnull
- public String getVariableName() {
- return "zip";
- }
-
- @Override
- @Nonnull
- public InputOutputVFS checkString(@Nonnull CodecContext context,
- @Nonnull final String string) throws ParsingException {
- RunnableHooks hooks = context.getRunnableHooks();
- try {
- final ReadWriteZipFS vfs = new ReadWriteZipFS(
- new OutputZipFile(context.getWorkingDirectory(), string, hooks, existence, change));
- return new GenericInputOutputVFS(vfs);
- } catch (IOException e) {
- throw new ParsingException(e.getMessage(), e);
- }
- }
-}
diff --git a/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java b/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java
index 00f2f03..12f7868 100644
--- a/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java
+++ b/sched/src/com/android/sched/vfs/CaseInsensitiveFS.java
@@ -47,6 +47,7 @@ import java.util.EnumSet;
import java.util.Set;
import javax.annotation.CheckForNull;
+import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
/**
@@ -81,8 +82,10 @@ public class CaseInsensitiveFS extends BaseVFS<CaseInsensitiveVDir, CaseInsensit
"sched.vfs.case-insensitive.debug",
"generate an index file '" + DEBUG_NAME + "' for debugging purpose").addDefaultValue(false);
- private final int nbGroup;
- private final int szGroup;
+ @Nonnegative
+ private final int numGroups;
+ @Nonnegative
+ private final int groupSize;
@Nonnull
private final MessageDigestFactory mdf;
private final boolean debug;
@@ -198,7 +201,7 @@ public class CaseInsensitiveFS extends BaseVFS<CaseInsensitiveVDir, CaseInsensit
}
@SuppressWarnings("unchecked")
- public CaseInsensitiveFS(@Nonnull VFS vfs, int nbGroup, int szGroup,
+ public CaseInsensitiveFS(@Nonnull VFS vfs, int numGroups, int groupSize,
@Nonnull MessageDigestFactory mdf, boolean debug) throws WrongVFSFormatException {
this.vfs = (BaseVFS<BaseVDir, BaseVFile>) vfs;
@@ -207,8 +210,8 @@ public class CaseInsensitiveFS extends BaseVFS<CaseInsensitiveVDir, CaseInsensit
capabilities.add(Capabilities.UNIQUE_ELEMENT);
this.capabilities = Collections.unmodifiableSet(capabilities);
- this.nbGroup = nbGroup;
- this.szGroup = szGroup;
+ this.numGroups = numGroups;
+ this.groupSize = groupSize;
this.mdf = mdf;
this.debug = debug;
@@ -568,8 +571,8 @@ public class CaseInsensitiveFS extends BaseVFS<CaseInsensitiveVDir, CaseInsensit
StringBuffer sb = new StringBuffer();
int idx = 0;
try {
- for (int groupIdx = 0; groupIdx < nbGroup; groupIdx++) {
- for (int letterIdx = 0; letterIdx < szGroup; letterIdx++) {
+ for (int groupIdx = 0; groupIdx < numGroups; groupIdx++) {
+ for (int letterIdx = 0; letterIdx < groupSize; letterIdx++) {
sb.append(digest[idx++]);
}
sb.append('/');
diff --git a/sched/src/com/android/sched/vfs/ReadWriteZipFS.java b/sched/src/com/android/sched/vfs/ReadWriteZipFS.java
index 56159c7..7d4e88c 100644
--- a/sched/src/com/android/sched/vfs/ReadWriteZipFS.java
+++ b/sched/src/com/android/sched/vfs/ReadWriteZipFS.java
@@ -16,6 +16,7 @@
package com.android.sched.vfs;
+import com.android.sched.util.config.MessageDigestFactory;
import com.android.sched.util.file.CannotCreateFileException;
import com.android.sched.util.file.CannotDeleteFileException;
import com.android.sched.util.file.CannotSetPermissionException;
@@ -52,7 +53,8 @@ public class ReadWriteZipFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS
@Nonnull
private final File dir;
- public ReadWriteZipFS(@Nonnull OutputZipFile file)
+ public ReadWriteZipFS(@Nonnull OutputZipFile file, int numGroups, int groupSize,
+ @Nonnull MessageDigestFactory mdf, boolean debug)
throws NotDirectoryException,
WrongPermissionException,
CannotSetPermissionException,
@@ -61,8 +63,15 @@ public class ReadWriteZipFS extends BaseVFS<BaseVDir, BaseVFile> implements VFS
CannotCreateFileException {
int permissions = Permission.READ | Permission.WRITE;
dir = Files.createTempDir();
- CachedDirectFS workVFS = new CachedDirectFS(new Directory(dir.getPath(), null,
- Existence.MUST_EXIST, permissions, ChangePermission.NOCHANGE), permissions);
+ VFS workVFS;
+ try {
+ workVFS = new CaseInsensitiveFS(new CachedDirectFS(new Directory(dir.getPath(),
+ null, Existence.MUST_EXIST, permissions, ChangePermission.NOCHANGE), permissions),
+ numGroups, groupSize, mdf, debug);
+ } catch (WrongVFSFormatException e) {
+ // Directory is empty, so this cannot happen
+ throw new AssertionError(e);
+ }
WriteZipFS finalVFS = new WriteZipFS(file);
this.vfs = new VFSToVFSWrapper(workVFS, finalVFS);
}
diff --git a/sched/tests/com/android/sched/vfs/VFSTest.java b/sched/tests/com/android/sched/vfs/VFSTest.java
index 45a4b04..b056e42 100644
--- a/sched/tests/com/android/sched/vfs/VFSTest.java
+++ b/sched/tests/com/android/sched/vfs/VFSTest.java
@@ -269,19 +269,11 @@ public class VFSTest {
String path = file.getAbsolutePath();
Assert.assertTrue(file.delete());
- Provider.Service sha1 = null;
- for (Provider provider : Security.getProviders()) {
- for (Provider.Service service : provider.getServices()) {
- if (service.getType().equals("MessageDigest") && service.getAlgorithm().equals("SHA")) {
- sha1 = service;
- }
- }
- }
- Assert.assertNotNull(sha1);
+ Provider.Service sha1 = getSha1Service();
ioVFS1 = new GenericInputOutputVFS(new MessageDigestFS(new DirectFS(new Directory(path,
null, Existence.NOT_EXIST, Permission.WRITE, ChangePermission.NOCHANGE),
- Permission.READ | Permission.WRITE), new MessageDigestFactory(sha1)));
+ Permission.READ | Permission.WRITE), new MessageDigestFactory(getSha1Service())));
testOutputVFS(ioVFS1);
testDelete(ioVFS1);
@@ -787,8 +779,11 @@ public class VFSTest {
try {
file = File.createTempFile("vfs", ".zip");
String path = file.getAbsolutePath();
+ Provider.Service sha1 = getSha1Service();
zipVFS = new GenericInputOutputVFS(new ReadWriteZipFS(
- new OutputZipFile(path, null, Existence.MAY_EXIST, ChangePermission.NOCHANGE)));
+ new OutputZipFile(path, null, Existence.MAY_EXIST, ChangePermission.NOCHANGE),
+ /* numGroups = */ 1, /* groupSize = */ 2,
+ new MessageDigestFactory(sha1), /* debug = */ false));
testOutputVFS(zipVFS);
testDelete(zipVFS);
// checkZipLocations(zipVFS);
@@ -997,4 +992,18 @@ public class VFSTest {
return string;
}
+ @Nonnull
+ private static Provider.Service getSha1Service() {
+ Provider.Service sha1 = null;
+ for (Provider provider : Security.getProviders()) {
+ for (Provider.Service service : provider.getServices()) {
+ if (service.getType().equals("MessageDigest") && service.getAlgorithm().equals("SHA")) {
+ sha1 = service;
+ }
+ }
+ }
+ Assert.assertNotNull(sha1);
+ return sha1;
+ }
+
}