aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2015-06-30 18:19:59 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-06-30 19:03:18 +0000
commit835d647ea6ccfba3d51acfdb8bcb4da8d099f84a (patch)
tree13cd36e7be5de532cfc6840cdb59f87f958d5319 /src/main/java/com
parenta8352e92a5dfb6e9453c742744a52c9b36ad4393 (diff)
Fix permissions for non-posix zip files
-- MOS_MIGRATED_REVID=97245351
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/ZipFunction.java32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipFunction.java
index 8e32cad040..17116199e7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipFunction.java
@@ -77,16 +77,15 @@ public class ZipFunction implements SkyFunction {
private void extractZipEntry(ZipReader reader, ZipFileEntry entry, Path destinationDirectory)
throws IOException {
- PathFragment relativePath = new PathFragment(entry.getName());
+ String relativeString = entry.getName();
+ PathFragment relativePath = new PathFragment(relativeString);
if (relativePath.isAbsolute()) {
throw new IOException(
String.format("Failed to extract %s, zipped paths cannot be absolute", relativePath));
}
Path outputPath = destinationDirectory.getRelative(relativePath);
+ int permissions = getPermissions(entry.getExternalAttributes(), relativeString);
FileSystemUtils.createDirectoryAndParents(outputPath.getParentDirectory());
- // Posix permissions are in the high-order 2 bytes of the external attributes. After this
- // operation, permissions holds 0100755 (or 040755 for directories).
- int permissions = entry.getExternalAttributes() >>> 16;
boolean isDirectory = (permissions & 040000) == 040000;
if (isDirectory) {
FileSystemUtils.createDirectoryAndParents(outputPath);
@@ -110,4 +109,29 @@ public class ZipFunction implements SkyFunction {
return null;
}
+ private int getPermissions(int permissions, String path) throws IOException {
+ // Posix permissions are in the high-order 2 bytes of the external attributes. After this
+ // operation, permissions holds 0100755 (or 040755 for directories).
+ int shiftedPermissions = permissions >>> 16;
+ if (shiftedPermissions != 0) {
+ return shiftedPermissions;
+ }
+
+ // If this was zipped up on FAT, it won't have posix permissions set. Instead, this
+ // checks if the filename ends with / (for directories) and extra attributes set to 0 for
+ // files. From https://github.com/miloyip/rapidjson/archive/v1.0.2.zip, it looks like
+ // executables end up with "normal" (posix) permissions (oddly), so they'll be handled above.
+ if (path.endsWith("/")) {
+ // Directory.
+ return 040755;
+ } else if (permissions == 0) {
+ // File.
+ return 010644;
+ }
+
+ // No idea.
+ throw new IOException("Unrecognized file mode for " + path + ": 0x"
+ + Integer.toHexString(permissions));
+ }
+
}