Skip to content

Commit 8b4eabe

Browse files
authored
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
1 parent 3bd7387 commit 8b4eabe

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import java.nio.file.attribute.AclEntryPermission;
3333
import java.nio.file.attribute.AclEntryType;
3434
import java.nio.file.attribute.AclFileAttributeView;
35+
import java.nio.file.attribute.FileOwnerAttributeView;
3536
import java.nio.file.attribute.PosixFilePermission;
3637
import java.nio.file.attribute.UserPrincipal;
3738
import java.util.HashSet;
39+
import java.util.Locale;
3840
import java.util.Set;
3941
import java.util.logging.Logger;
4042

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

5557
private static final boolean IS_WINDOWS = StandardSystemProperty.OS_NAME.value()
56-
.startsWith("WINDOWS");
58+
.toLowerCase(Locale.ENGLISH).startsWith("windows");
5759

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

156158
static void setPermissionsToOwnerOnlyWindows(File file) throws IOException {
157159
Path path = Paths.get(file.getAbsolutePath());
158-
UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService()
159-
.lookupPrincipalByName("OWNER@");
160+
FileOwnerAttributeView fileAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
161+
UserPrincipal owner = fileAttributeView.getOwner();
160162

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

0 commit comments

Comments
 (0)