Skip to content
Permalink
Browse files
fix: incorrect check for Windows OS in FileDataStoreFactory (#927)
* fix: incorrect check for Windows OS in FileDataStoreFactory
* fix: properly get file owner on windows in FileDataStoreFactory
* refactor: use toLowerCase instead of regionMatches in FileDataStoreFactory
  • Loading branch information
diesieben07 committed Mar 25, 2020
1 parent 3bd7387 commit 8b4eabe985794fc64ad6a4a53f8f96201cf73fb8
Showing with 5 additions and 3 deletions.
  1. +5 −3 google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java
@@ -32,9 +32,11 @@
import java.nio.file.attribute.AclEntryPermission;
import java.nio.file.attribute.AclEntryType;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.logging.Logger;

@@ -53,7 +55,7 @@ public class FileDataStoreFactory extends AbstractDataStoreFactory {
private static final Logger LOGGER = Logger.getLogger(FileDataStoreFactory.class.getName());

private static final boolean IS_WINDOWS = StandardSystemProperty.OS_NAME.value()
.startsWith("WINDOWS");
.toLowerCase(Locale.ENGLISH).startsWith("windows");

/** Directory to store data. */
private final File dataDirectory;
@@ -155,8 +157,8 @@ static void setPermissionsToOwnerOnly(File file) throws IOException {

static void setPermissionsToOwnerOnlyWindows(File file) throws IOException {
Path path = Paths.get(file.getAbsolutePath());
UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService()
.lookupPrincipalByName("OWNER@");
FileOwnerAttributeView fileAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
UserPrincipal owner = fileAttributeView.getOwner();

// get view
AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);

0 comments on commit 8b4eabe

Please sign in to comment.