提交 9f663ab8 编写于 作者: K kaddepalli

8194546: Choosier FileManagers

Reviewed-by: prr, serb, skoivu, rhalade
上级 9c8d5871
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -677,7 +677,7 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -677,7 +677,7 @@ final class Win32ShellFolder2 extends ShellFolder {
} }
try { try {
return invoke(new Callable<File[]>() { File[] files = invoke(new Callable<File[]>() {
public File[] call() throws InterruptedException { public File[] call() throws InterruptedException {
if (!isDirectory()) { if (!isDirectory()) {
return null; return null;
...@@ -731,6 +731,8 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -731,6 +731,8 @@ final class Win32ShellFolder2 extends ShellFolder {
? new File[0] ? new File[0]
: list.toArray(new ShellFolder[list.size()]); : list.toArray(new ShellFolder[list.size()]);
} }
return Win32ShellFolderManager2.checkFiles(files);
}, InterruptedException.class); }, InterruptedException.class);
} catch (InterruptedException e) { } catch (InterruptedException e) {
return new File[0]; return new File[0];
......
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -379,21 +379,30 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -379,21 +379,30 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return null; return null;
} }
private File checkFile(File file) { private static File checkFile(File file) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
return (sm == null || file == null) ? file : checkFile(file, sm); return (sm == null || file == null) ? file : checkFile(file, sm);
} }
private File checkFile(File file, SecurityManager sm) { private static File checkFile(File file, SecurityManager sm) {
try { try {
sm.checkRead(file.getPath()); sm.checkRead(file.getPath());
if (file instanceof Win32ShellFolder2) {
Win32ShellFolder2 f = (Win32ShellFolder2)file;
if (f.isLink()) {
Win32ShellFolder2 link = (Win32ShellFolder2)f.getLinkLocation();
if (link != null)
sm.checkRead(link.getPath());
}
}
return file; return file;
} catch (SecurityException se) { } catch (SecurityException se) {
return null; return null;
} }
} }
private File[] checkFiles(File[] files) { static File[] checkFiles(File[] files) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm == null || files == null || files.length == 0) { if (sm == null || files == null || files.length == 0) {
return files; return files;
...@@ -401,7 +410,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -401,7 +410,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return checkFiles(Arrays.stream(files), sm); return checkFiles(Arrays.stream(files), sm);
} }
private File[] checkFiles(List<File> files) { private static File[] checkFiles(List<File> files) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm == null || files.isEmpty()) { if (sm == null || files.isEmpty()) {
return files.toArray(new File[files.size()]); return files.toArray(new File[files.size()]);
...@@ -409,7 +418,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -409,7 +418,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return checkFiles(files.stream(), sm); return checkFiles(files.stream(), sm);
} }
private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) { private static File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
return filesStream.filter((file) -> checkFile(file, sm) != null) return filesStream.filter((file) -> checkFile(file, sm) != null)
.toArray(File[]::new); .toArray(File[]::new);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册