1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-10 18:45:26 +02:00

Bug 150143 - fixed LocalFileService to pay attention to the "files only" option on filter definitions.

This commit is contained in:
David Dykstal 2006-11-07 02:36:32 +00:00
parent 62de603571
commit 3f6f7d8f51

View file

@ -123,11 +123,11 @@ public class LocalFileService extends AbstractFileService implements IFileServic
return _isWindows; return _isWindows;
} }
public class LocalFileNameFilter implements FilenameFilter public class LocalFileNameFilter implements FilenameFilter {
{
private IMatcher _matcher; private IMatcher _matcher;
public LocalFileNameFilter(String filter) private int type;
{
public LocalFileNameFilter(String filter, int type) {
if (filter == null) { if (filter == null) {
filter = "*"; //$NON-NLS-1$ filter = "*"; //$NON-NLS-1$
} }
@ -137,13 +137,25 @@ public class LocalFileService extends AbstractFileService implements IFileServic
} else { } else {
_matcher = new NamePatternMatcher(filter); _matcher = new NamePatternMatcher(filter);
} }
this.type = type;
} }
public boolean accept(File dir, String name)
{ public boolean accept(File dir, String name) {
return _matcher.matches(name); boolean result = false;
File entry = new File(dir, name);
if (entry.exists()) {
if (entry.isFile()) {
result = _matcher.matches(name);
} else if (entry.isDirectory()) {
if (type == FILE_TYPE_FILES_AND_FOLDERS || type == FILE_TYPE_FOLDERS) {
result = true;
}
}
}
return result;
} }
public boolean isGeneric()
{ public boolean isGeneric() {
boolean result = true; boolean result = true;
if (_matcher instanceof NamePatternMatcher) { if (_matcher instanceof NamePatternMatcher) {
NamePatternMatcher new_name = (NamePatternMatcher) _matcher; NamePatternMatcher new_name = (NamePatternMatcher) _matcher;
@ -589,87 +601,58 @@ public class LocalFileService extends AbstractFileService implements IFileServic
return true; return true;
} }
protected IHostFile[] internalFetch(IProgressMonitor monitor, String remoteParent, String fileFilter, int type) protected IHostFile[] internalFetch(IProgressMonitor monitor, String remoteParent, String fileFilter, int type) {
{ LocalFileNameFilter fFilter = new LocalFileNameFilter(fileFilter, type);
LocalFileNameFilter fFilter = new LocalFileNameFilter(fileFilter);
File localParent = new File(remoteParent); File localParent = new File(remoteParent);
// if the system type is Windows, we get the canonical path so that we have the correct case in the path // if the system type is Windows, we get the canonical path so that we have the correct case in the path
// this is needed because Windows paths are case insensitive // this is needed because Windows paths are case insensitive
if (isWindows()) { if (isWindows()) {
try { try {
localParent = localParent.getCanonicalFile(); localParent = localParent.getCanonicalFile();
} } catch (IOException e) {
catch (IOException e) {
System.out.println("Can not get canonical path: " + localParent.getAbsolutePath()); System.out.println("Can not get canonical path: " + localParent.getAbsolutePath());
} }
} }
if (remoteParent.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) {
if (remoteParent.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR))
{
remoteParent = remoteParent.substring(0, remoteParent.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length()); remoteParent = remoteParent.substring(0, remoteParent.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length());
} }
boolean isVirtual = ArchiveHandlerManager.isVirtual(remoteParent); boolean isVirtual = ArchiveHandlerManager.isVirtual(remoteParent);
boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(localParent); boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(localParent);
if (isVirtual || isArchive) if (isVirtual || isArchive) {
{ try {
try
{
VirtualChild[] contents = null; VirtualChild[] contents = null;
File theFile = getContainingArchive(localParent); File theFile = getContainingArchive(localParent);
if (isArchive) {
if (isArchive)
{
contents = ArchiveHandlerManager.getInstance().getContents(localParent, ""); //$NON-NLS-1$ contents = ArchiveHandlerManager.getInstance().getContents(localParent, ""); //$NON-NLS-1$
} } else if (isVirtual) {
else if (isVirtual)
{
AbsoluteVirtualPath avp = new AbsoluteVirtualPath(remoteParent); AbsoluteVirtualPath avp = new AbsoluteVirtualPath(remoteParent);
contents = ArchiveHandlerManager.getInstance().getContents(theFile, avp.getVirtualPart()); contents = ArchiveHandlerManager.getInstance().getContents(theFile, avp.getVirtualPart());
} }
if (contents == null) {
if (contents == null)
{
return null; return null;
} }
IHostFile[] results = new LocalVirtualHostFile[contents.length]; IHostFile[] results = new LocalVirtualHostFile[contents.length];
for (int i = 0; i < contents.length; i++) {
for (int i = 0; i < contents.length; i++)
{
results[i] = new LocalVirtualHostFile(contents[i]); results[i] = new LocalVirtualHostFile(contents[i]);
} }
return results; return results;
} } catch (IOException e) {
catch (IOException e)
{
// FIXME: Do something! // FIXME: Do something!
return null; return null;
} }
} } else {
else
{
// allow cancel before doing the os query // allow cancel before doing the os query
if (monitor != null && monitor.isCanceled()) if (monitor != null && monitor.isCanceled()) {
{
return null; return null;
} }
if (!fFilter.isGeneric()) if (!fFilter.isGeneric()) {
{
File file = new File(localParent, fileFilter); File file = new File(localParent, fileFilter);
return convertToHostFiles(new File[] { file }, type); return convertToHostFiles(new File[] { file }, type);
} }
if (localParent.exists()) if (localParent.exists()) {
{
File[] files = localParent.listFiles(fFilter); File[] files = localParent.listFiles(fFilter);
return convertToHostFiles(files, type); return convertToHostFiles(files, type);
} } else {
else
{
return new IHostFile[0]; return new IHostFile[0];
} }
} }