mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 21:15:23 +02:00
[250168] fixes for search
This commit is contained in:
parent
eb66a5e2ff
commit
ceae7726eb
3 changed files with 199 additions and 134 deletions
|
@ -37,6 +37,7 @@
|
||||||
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
|
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
|
||||||
* David McKnight (IBM) - [244277] [dstore] NPE on file save from old client
|
* David McKnight (IBM) - [244277] [dstore] NPE on file save from old client
|
||||||
* David McKnight (IBM) - [246234] Change of file permissions changes the file owner
|
* David McKnight (IBM) - [246234] Change of file permissions changes the file owner
|
||||||
|
* David McKnight (IBM) - [250168] handleCommand should not blindly set the status to "done"
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.dstore.universal.miners;
|
package org.eclipse.rse.dstore.universal.miners;
|
||||||
|
@ -62,6 +63,7 @@ import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CopySingleThr
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFileThread;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFileThread;
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFolderThread;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.CreateFolderThread;
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.DeleteThread;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.DeleteThread;
|
||||||
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileClassifier;
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileDescriptors;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileDescriptors;
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileQueryThread;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.FileQueryThread;
|
||||||
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.RenameThread;
|
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.RenameThread;
|
||||||
|
@ -234,7 +236,8 @@ public class UniversalFileSystemMiner extends Miner {
|
||||||
UniversalServerUtilities.logError(CLASSNAME,
|
UniversalServerUtilities.logError(CLASSNAME,
|
||||||
"Invalid query to handlecommand", null, _dataStore); //$NON-NLS-1$
|
"Invalid query to handlecommand", null, _dataStore); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return statusDone(status);
|
//return statusDone(status);
|
||||||
|
return status; // can't assume operation is done since it could be done via a thread
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status)
|
private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status)
|
||||||
|
@ -315,7 +318,7 @@ public class UniversalFileSystemMiner extends Miner {
|
||||||
//return status;
|
//return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return statusDone(status);
|
return status; // search is in the thread, so it's not done yet
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataElement handleCancel(DataElement subject, DataElement status) {
|
public DataElement handleCancel(DataElement subject, DataElement status) {
|
||||||
|
@ -1101,11 +1104,10 @@ public class UniversalFileSystemMiner extends Miner {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to obtain the classificatoin string of file or folder.
|
* Method to obtain the classification string of file or folder.
|
||||||
*/
|
*/
|
||||||
protected String getClassificationString(String s) {
|
protected String getClassificationString(String s) {
|
||||||
|
|
||||||
//StringTokenizer tokenizer = new StringTokenizer(s, IServiceConstants.TOKEN_SEPARATOR);
|
|
||||||
String[] str = s.split("\\"+IServiceConstants.TOKEN_SEPARATOR); //$NON-NLS-1$
|
String[] str = s.split("\\"+IServiceConstants.TOKEN_SEPARATOR); //$NON-NLS-1$
|
||||||
int tokens = str.length;
|
int tokens = str.length;
|
||||||
if (tokens < 10)
|
if (tokens < 10)
|
||||||
|
@ -1904,8 +1906,47 @@ public class UniversalFileSystemMiner extends Miner {
|
||||||
|
|
||||||
String result = getFilePermission(file, PERMISSION_ALL);
|
String result = getFilePermission(file, PERMISSION_ALL);
|
||||||
status.setAttribute(DE.A_SOURCE, result);
|
status.setAttribute(DE.A_SOURCE, result);
|
||||||
statusDone(status);
|
|
||||||
|
|
||||||
|
|
||||||
|
// for z/os, also need to update the classification if this is a symbolic link
|
||||||
|
String theOS = System.getProperty("os.name"); //$NON-NLS-1$
|
||||||
|
boolean isZ = theOS.toLowerCase().startsWith("z");//$NON-NLS-1$
|
||||||
|
if (isZ){
|
||||||
|
String path = file.getAbsolutePath();
|
||||||
|
try {
|
||||||
|
String canonical = file.getCanonicalPath();
|
||||||
|
if (!path.equals(canonical)){
|
||||||
|
// reset the properties
|
||||||
|
String properties = setProperties(file, false);
|
||||||
|
|
||||||
|
// fileType
|
||||||
|
String fileType = file.isFile() ? "file" : "directory"; //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
|
||||||
|
// classification
|
||||||
|
StringBuffer type = new StringBuffer(FileClassifier.STR_SYMBOLIC_LINK);
|
||||||
|
type.append('(');
|
||||||
|
type.append(fileType);
|
||||||
|
type.append(')');
|
||||||
|
type.append(':');
|
||||||
|
type.append(canonical);
|
||||||
|
|
||||||
|
StringBuffer classifiedProperties = new StringBuffer(properties);
|
||||||
|
classifiedProperties.append('|');
|
||||||
|
classifiedProperties.append(type);
|
||||||
|
|
||||||
|
subject.setAttribute(DE.A_SOURCE, classifiedProperties.toString());
|
||||||
|
_dataStore.refresh(subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SystemMessageException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
statusDone(status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* David McKnight (IBM) - [214378] canonical path not required - problem is in the client
|
* David McKnight (IBM) - [214378] canonical path not required - problem is in the client
|
||||||
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
|
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
|
||||||
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
|
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
|
||||||
|
* David McKnight (IBM) - [250168] handle malformed binary and always resolve canonical paths
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
|
package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
|
||||||
|
@ -25,7 +26,6 @@ package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
// search isn't finished.
|
// search isn't finished.
|
||||||
// _miner.statusDone(_status);
|
// _miner.statusDone(_status);
|
||||||
_status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
|
_status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
|
||||||
_dataStore.refresh(_status, true); // true indicates refresh immediately
|
_dataStore.refresh(_status); // true indicates refresh immediately
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,20 +155,22 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
_isCancelled = true;
|
_isCancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasSearchedDirectory(File file)
|
protected boolean hasSearched(File file)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
return _alreadySearched.contains(file.getCanonicalFile());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
_dataStore.trace(e);
|
|
||||||
return _alreadySearched.contains(file);
|
return _alreadySearched.contains(file);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void internalSearch(File theFile, int depth) throws SystemMessageException {
|
protected void internalSearch(File theFile, int depth) throws SystemMessageException {
|
||||||
|
try {
|
||||||
|
theFile = theFile.getCanonicalFile();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSearched(theFile)) {
|
||||||
|
|
||||||
|
_alreadySearched.add(theFile);
|
||||||
|
|
||||||
// is it a directory?
|
// is it a directory?
|
||||||
boolean isDirectory = theFile.isDirectory();
|
boolean isDirectory = theFile.isDirectory();
|
||||||
|
@ -178,7 +180,6 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
|
|
||||||
String absPath = theFile.getAbsolutePath();
|
String absPath = theFile.getAbsolutePath();
|
||||||
|
|
||||||
|
|
||||||
String compareStr = theFile.getName();
|
String compareStr = theFile.getName();
|
||||||
|
|
||||||
// is it a virtual file?
|
// is it a virtual file?
|
||||||
|
@ -273,19 +274,6 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
// children and search those
|
// children and search those
|
||||||
if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives()))
|
if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives()))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!hasSearchedDirectory(theFile)) {
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_alreadySearched.add(theFile.getCanonicalFile());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
_dataStore.trace(e);
|
|
||||||
_alreadySearched.add(theFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] children = null;
|
File[] children = null;
|
||||||
|
|
||||||
// if the file is an archive or a virtual directory, then get the children from
|
// if the file is an archive or a virtual directory, then get the children from
|
||||||
|
@ -351,10 +339,19 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||||
BufferedReader bufReader = new BufferedReader(reader);
|
BufferedReader bufReader = new BufferedReader(reader);
|
||||||
|
|
||||||
|
// test for unreadable binary
|
||||||
|
if (isUnreadableBinary(bufReader)){
|
||||||
|
// search some other way?
|
||||||
|
long size = theFile.length();
|
||||||
|
if (simpleSearch(inputStream, size, _stringMatcher)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
|
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
|
||||||
|
|
||||||
SystemSearchLineMatch[] matches = locator.locateMatches();
|
SystemSearchLineMatch[] matches = locator.locateMatches();
|
||||||
|
|
||||||
boolean foundMatches = ((matches != null) && (matches.length > 0));
|
boolean foundMatches = ((matches != null) && (matches.length > 0));
|
||||||
|
|
||||||
if (foundMatches) {
|
if (foundMatches) {
|
||||||
|
@ -363,6 +360,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
|
|
||||||
return foundMatches;
|
return foundMatches;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
UniversalServerUtilities.logError(_miner.getName(), "Error occured when trying to locate matches", e, _dataStore); //$NON-NLS-1$
|
UniversalServerUtilities.logError(_miner.getName(), "Error occured when trying to locate matches", e, _dataStore); //$NON-NLS-1$
|
||||||
remoteFile.setAttribute(DE.A_VALUE, e.getMessage());
|
remoteFile.setAttribute(DE.A_VALUE, e.getMessage());
|
||||||
|
@ -370,6 +368,32 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean simpleSearch(FileInputStream stream, long size, SystemSearchStringMatcher matcher)
|
||||||
|
{
|
||||||
|
byte[] bytes = new byte[(int)size];
|
||||||
|
try {
|
||||||
|
stream.read(bytes, 0, (int)size);
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
}
|
||||||
|
|
||||||
|
String str = new String(bytes);
|
||||||
|
return _stringMatcher.matches(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUnreadableBinary(BufferedReader reader){
|
||||||
|
try {
|
||||||
|
reader.mark(1);
|
||||||
|
reader.read();
|
||||||
|
reader.reset();
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean doesFilePatternMatch(String compareStr) {
|
protected boolean doesFilePatternMatch(String compareStr) {
|
||||||
return _fileNameMatcher.matches(compareStr);
|
return _fileNameMatcher.matches(compareStr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
* David McKnight (IBM) - [236039][dstore][efs] DStoreInputStream can report EOF too early - clean up how it waits for the local temp file to be created
|
* David McKnight (IBM) - [236039][dstore][efs] DStoreInputStream can report EOF too early - clean up how it waits for the local temp file to be created
|
||||||
* David McKnight (IBM) - [240710] [dstore] DStoreFileService.getFile() fails with NPE for valid root files
|
* David McKnight (IBM) - [240710] [dstore] DStoreFileService.getFile() fails with NPE for valid root files
|
||||||
* David McKnight (IBM) - [249544] Save conflict dialog appears when saving files in the editor
|
* David McKnight (IBM) - [249544] Save conflict dialog appears when saving files in the editor
|
||||||
* David McKnight (IBM) - [249544] some backward compatibility issues with old IBM dstore server
|
* David McKnight (IBM) - [250168] some backward compatibility issues with old IBM dstore server
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.services.dstore.files;
|
package org.eclipse.rse.internal.services.dstore.files;
|
||||||
|
|
Loading…
Add table
Reference in a new issue