mirror of https://github.com/apache/jclouds.git
Fixes a windows locale bug with the "Everyone" principal
This commit is contained in:
parent
3c1588527d
commit
2efcb2c5a9
|
@ -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;
|
||||
|
@ -99,13 +101,41 @@ public class Utils {
|
|||
throw new IOException("Could not delete: " + file.toPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue