diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2015-06-12 15:45:25 +0200 |
---|---|---|
committer | Benoit Lamarche <benoitlamarche@google.com> | 2015-06-17 18:26:04 +0200 |
commit | f01db511461651a993ae2f33a9c9b19a7c1fe515 (patch) | |
tree | 33d5e43b59f5d0b87b52d0a8479d798cfe8eb656 /sched/src/com/android/sched | |
parent | 325b47a0195f7ee1a711f87bee42c8293523f558 (diff) | |
download | toolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.tar.gz toolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.tar.bz2 toolchain_jack-f01db511461651a993ae2f33a9c9b19a7c1fe515.zip |
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
Diffstat (limited to 'sched/src/com/android/sched')
4 files changed, 31 insertions, 83 deletions
diff --git a/sched/src/com/android/sched/util/codec/ZipFSCodec.java b/sched/src/com/android/sched/util/codec/ZipFSCodec.java index 4cc8bcef..835a9f1a 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 6c6da206..00000000 --- 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 00f2f030..12f78688 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 56159c78..7d4e88c7 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); } |