Skip to content

Commit

Permalink
Implement cache.
Browse files Browse the repository at this point in the history
Former-commit-id: 600bda47655194aca82effa3eb260ae2f2544953
  • Loading branch information
dkocher committed May 14, 2014
1 parent 2c547ea commit 1eaacb5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion source/ch/cyberduck/core/sftp/SFTPFindFeature.java
Expand Up @@ -17,6 +17,7 @@
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/

import ch.cyberduck.core.AttributedList;
import ch.cyberduck.core.Cache;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.exception.BackgroundException;
Expand All @@ -32,31 +33,54 @@ public class SFTPFindFeature implements Find {

private SFTPSession session;

private Cache cache;

public SFTPFindFeature(final SFTPSession session) {
this.session = session;
this.cache = Cache.empty();
}

@Override
public boolean find(final Path file) throws BackgroundException {
if(file.isRoot()) {
return true;
}
final AttributedList<Path> list;
if(cache.containsKey(file.getParent().getReference())) {
list = cache.get(file.getParent().getReference());
}
else {
list = new AttributedList<Path>();
cache.put(file.getParent().getReference(), list);
}
if(list.contains(file.getReference())) {
// Previously found
return true;
}
if(list.attributes().getHidden().contains(file)) {
// Previously not found
return false;
}
try {
try {
return session.sftp().canonicalize(file.getAbsolute()) != null;
session.sftp().canonicalize(file.getAbsolute());
list.add(file);
return true;
}
catch(IOException e) {
throw new SFTPExceptionMappingService().map(e);
}
}
catch(NotfoundException e) {
// We expect SSH_FXP_STATUS if the file is not found
list.attributes().addHidden(file);
return false;
}
}

@Override
public Find withCache(final Cache cache) {
this.cache = cache;
return this;
}
}

0 comments on commit 1eaacb5

Please sign in to comment.