From 7a3613a4dd2cb06d8a53990a7efd96fd52b3faaf Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Sat, 28 Dec 2019 23:14:16 +0100 Subject: [PATCH 1/3] fix: incorrect check for Windows OS in FileDataStoreFactory --- .../com/google/api/client/util/store/FileDataStoreFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java index 230af26e2..3dba2c3d9 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java +++ b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java @@ -53,7 +53,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"); + .regionMatches(true, 0, "WINDOWS", 0, "WINDOWS".length()); /** Directory to store data. */ private final File dataDirectory; From c97c34ea6b097c89867ef27361c5713935bf0ccb Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Sat, 28 Dec 2019 23:51:13 +0100 Subject: [PATCH 2/3] fix: properly get file owner on windows in FileDataStoreFactory --- .../google/api/client/util/store/FileDataStoreFactory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java index 3dba2c3d9..f38e557b2 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java +++ b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java @@ -32,6 +32,7 @@ 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; @@ -155,8 +156,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); From 6bc4da2f09a0341e730663da84d1d6ebbffb8eec Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Sun, 29 Dec 2019 22:21:25 +0100 Subject: [PATCH 3/3] refactor: use toLowerCase instead of regionMatches in FileDataStoreFactory --- .../com/google/api/client/util/store/FileDataStoreFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java index f38e557b2..6114c2ae1 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java +++ b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java @@ -36,6 +36,7 @@ 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; @@ -54,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() - .regionMatches(true, 0, "WINDOWS", 0, "WINDOWS".length()); + .toLowerCase(Locale.ENGLISH).startsWith("windows"); /** Directory to store data. */ private final File dataDirectory;