You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by za...@apache.org on 2015/11/19 20:45:29 UTC

jclouds git commit: Fixes a windows locale bug with the "Everyone" principal

Repository: jclouds
Updated Branches:
  refs/heads/master 3c1588527 -> 2efcb2c5a


Fixes a windows locale bug with the "Everyone" principal


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2efcb2c5
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2efcb2c5
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2efcb2c5

Branch: refs/heads/master
Commit: 2efcb2c5a9fadc52bcac411898154735eea4a66a
Parents: 3c15885
Author: Zack Shoylev <za...@rackspace.com>
Authored: Fri Nov 13 01:16:25 2015 -0600
Committer: Zack Shoylev <za...@rackspace.com>
Committed: Thu Nov 19 11:50:15 2015 -0600

----------------------------------------------------------------------
 .../java/org/jclouds/filesystem/util/Utils.java | 36 ++++++++++++++++++--
 .../FilesystemStorageStrategyImplTest.java      | 15 ++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/2efcb2c5/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
index ec1f56a..6b7ec49 100644
--- a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
+++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java
@@ -18,8 +18,10 @@ package org.jclouds.filesystem.util;
 
 import static java.nio.file.FileSystems.getDefault;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.nio.file.AccessDeniedException;
 import java.nio.file.DirectoryNotEmptyException;
 import java.nio.file.Files;
@@ -100,12 +102,40 @@ public class Utils {
    }
 
    /**
+    * @return Localized name for the "Everyone" Windows principal.
+    */
+   public static final String getWindowsEveryonePrincipalName() {
+      if (isWindows()) {
+         try {
+            Process process = new ProcessBuilder("whoami", "/groups").start();
+            try {
+               String line;
+               try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+                  while ((line = reader.readLine()) != null) {
+                     if (line.indexOf("S-1-1-0") != -1) {
+                        return line.split(" ")[0];
+                     }
+                  }
+               }
+            } finally {
+               process.destroy();
+            }
+         } catch (IOException e) {
+         }
+      }
+      // Default/fallback value
+      return "Everyone";
+   }
+
+   public static final String WINDOWS_EVERYONE = getWindowsEveryonePrincipalName();
+
+   /**
     * @param path The path to a Windows file or directory.
     * @return true if path has permissions set to Everyone on windows. The exact permissions are not checked.
     */
    public static boolean isPrivate(Path path) throws IOException {
       UserPrincipal everyone = getDefault().getUserPrincipalLookupService()
-            .lookupPrincipalByName("Everyone");
+            .lookupPrincipalByName(WINDOWS_EVERYONE);
       AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(
             path, AclFileAttributeView.class);
       for (AclEntry aclEntry : aclFileAttributes.getAcl()) {
@@ -121,7 +151,7 @@ public class Utils {
     */
    public static void setPrivate(Path path) throws IOException {
       UserPrincipal everyone = getDefault().getUserPrincipalLookupService()
-            .lookupPrincipalByName("Everyone");
+            .lookupPrincipalByName(WINDOWS_EVERYONE);
       AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(
             path, AclFileAttributeView.class);
       CopyOnWriteArrayList<AclEntry> aclList = new CopyOnWriteArrayList(aclFileAttributes.getAcl());
@@ -138,7 +168,7 @@ public class Utils {
     */
    public static void setPublic(Path path) throws IOException {
       UserPrincipal everyone = getDefault().getUserPrincipalLookupService()
-            .lookupPrincipalByName("Everyone");
+            .lookupPrincipalByName(WINDOWS_EVERYONE);
       AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(
             path, AclFileAttributeView.class);
       List<AclEntry> list = aclFileAttributes.getAcl();

http://git-wip-us.apache.org/repos/asf/jclouds/blob/2efcb2c5/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
index c16c9b1..61f08fc 100644
--- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
+++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
@@ -37,6 +37,7 @@ import javax.inject.Provider;
 
 import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.domain.BlobBuilder;
+import org.jclouds.blobstore.domain.ContainerAccess;
 import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
 import org.jclouds.blobstore.options.ListContainerOptions;
 import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
@@ -127,6 +128,20 @@ public class FilesystemStorageStrategyImplTest {
       TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
    }
 
+   public void testCreateContainerAccess() {
+      boolean result;
+
+      TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
+      result = storageStrategy.createContainer(CONTAINER_NAME);
+      assertTrue(result, "Container not created");
+      TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
+
+      storageStrategy.setContainerAccess(CONTAINER_NAME, ContainerAccess.PRIVATE);
+      assertEquals(storageStrategy.getContainerAccess(CONTAINER_NAME), ContainerAccess.PRIVATE);
+      storageStrategy.setContainerAccess(CONTAINER_NAME, ContainerAccess.PUBLIC_READ);
+      assertEquals(storageStrategy.getContainerAccess(CONTAINER_NAME), ContainerAccess.PUBLIC_READ);
+   }
+
    public void testCreateContainer_ContainerAlreadyExists() {
       boolean result;