Skip to content

Commit

Permalink
fix: incorrect check for Windows OS in FileDataStoreFactory (#927)
Browse files Browse the repository at this point in the history
* 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 8b4eabe
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8b4eabe

Please sign in to comment.