Skip to content

Commit

Permalink
Fix #7353.
Browse files Browse the repository at this point in the history
Former-commit-id: 646e9e9543510d20b505d942f40c0f2098023c2c
  • Loading branch information
dkocher committed Jul 18, 2013
1 parent 31d3d41 commit f261b17
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions source/ch/cyberduck/core/sftp/SFTPListService.java
Expand Up @@ -22,11 +22,13 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Permission;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.NotfoundException;

import org.apache.log4j.Logger;

import java.io.IOException;

import ch.ethz.ssh2.SFTPException;
import ch.ethz.ssh2.SFTPv3DirectoryEntry;
import ch.ethz.ssh2.SFTPv3FileAttributes;

Expand Down Expand Up @@ -83,24 +85,34 @@ public AttributedList<Path> list(final Path directory) throws BackgroundExceptio
file.attributes().setAccessedDate(attributes.atime * 1000L);
}
if(attributes.isSymlink()) {
final String target = session.sftp().readLink(file.getAbsolute());
final int type;
final Path symlink;
if(target.startsWith(String.valueOf(Path.DELIMITER))) {
symlink = new Path(target, file.attributes().isFile() ? Path.FILE_TYPE : Path.DIRECTORY_TYPE);
}
else {
symlink = new Path(directory, target, file.attributes().isFile() ? Path.FILE_TYPE : Path.DIRECTORY_TYPE);
}
file.setSymlinkTarget(symlink);
final SFTPv3FileAttributes targetAttributes = session.sftp().stat(symlink.getAbsolute());
if(targetAttributes.isDirectory()) {
type = Path.SYMBOLIC_LINK_TYPE | Path.DIRECTORY_TYPE;
try {
final String target = session.sftp().readLink(file.getAbsolute());
final int type;
final Path symlink;
if(target.startsWith(String.valueOf(Path.DELIMITER))) {
symlink = new Path(target, file.attributes().isFile() ? Path.FILE_TYPE : Path.DIRECTORY_TYPE);
}
else {
symlink = new Path(directory, target, file.attributes().isFile() ? Path.FILE_TYPE : Path.DIRECTORY_TYPE);
}
file.setSymlinkTarget(symlink);
final SFTPv3FileAttributes targetAttributes = session.sftp().stat(symlink.getAbsolute());
if(targetAttributes.isDirectory()) {
type = Path.SYMBOLIC_LINK_TYPE | Path.DIRECTORY_TYPE;
}
else {
type = Path.SYMBOLIC_LINK_TYPE | Path.FILE_TYPE;
}
file.attributes().setType(type);
}
else {
type = Path.SYMBOLIC_LINK_TYPE | Path.FILE_TYPE;
catch(SFTPException e) {
if(new SFTPExceptionMappingService().map(e) instanceof NotfoundException) {
log.warn(String.format("Cannot read symbolic link target of %s", file));
}
else {
throw e;
}
}
file.attributes().setType(type);
}
children.add(file);
}
Expand Down

0 comments on commit f261b17

Please sign in to comment.