imario 2004/05/27 13:15:28
Modified: vfs/src/java/org/apache/commons/vfs/provider/ftp
FtpFileObject.java
Log:
transparently handle symbolic links, beside the file-type (which was the case
currently) now
content size
modification date
and children
are automatically fetched from the link destination.
Revision Changes Path
1.25 +59 -13
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
Index: FtpFileObject.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- FtpFileObject.java 25 May 2004 14:43:01 -0000 1.24
+++ FtpFileObject.java 27 May 2004 20:15:28 -0000 1.25
@@ -50,6 +50,7 @@
// Cached info
private FTPFile fileInfo;
private FTPFile[] children;
+ private FileObject linkDestination;
public FtpFileObject(final FileName name,
final FtpFileSystem fileSystem,
@@ -215,15 +216,39 @@
}
else if (fileInfo.isSymbolicLink())
{
- // TODO - add generic support for links
- final String path = fileInfo.getLink();
- final FileObject target = getParent().resolveFile(path);
- return target.getType();
+ return getLinkDestination().getType();
}
throw new FileSystemException("vfs.provider.ftp/get-type.error", getName());
}
+ private FileObject getLinkDestination() throws FileSystemException
+ {
+ if (linkDestination == null)
+ {
+ final String path = fileInfo.getLink();
+ FileName relativeTo = getName().getParent();
+ if (relativeTo == null)
+ {
+ relativeTo = getName();
+ }
+ FileName linkDestinationName = relativeTo.resolveName(path);
+ linkDestination = getFileSystem().resolveFile(linkDestinationName);
+ }
+
+ return linkDestination;
+ }
+
+ protected FileObject[] doListChildrenResolved() throws Exception
+ {
+ if (fileInfo.isSymbolicLink())
+ {
+ return getLinkDestination().getChildren();
+ }
+
+ return null;
+ }
+
/**
* Lists the children of the file.
*/
@@ -328,7 +353,14 @@
*/
protected long doGetContentSize() throws Exception
{
- return fileInfo.getSize();
+ if (fileInfo.isSymbolicLink())
+ {
+ return getLinkDestination().getContent().getSize();
+ }
+ else
+ {
+ return fileInfo.getSize();
+ }
}
/**
@@ -338,14 +370,21 @@
*/
protected long doGetLastModifiedTime() throws Exception
{
- Calendar timestamp = fileInfo.getTimestamp();
- if (timestamp == null)
+ if (fileInfo.isSymbolicLink())
{
- return 0L;
+ return getLinkDestination().getContent().getLastModifiedTime();
}
else
{
- return (timestamp.getTime().getTime());
+ Calendar timestamp = fileInfo.getTimestamp();
+ if (timestamp == null)
+ {
+ return 0L;
+ }
+ else
+ {
+ return (timestamp.getTime().getTime());
+ }
}
}
@@ -357,10 +396,17 @@
*/
protected void doSetLastModifiedTime(final long modtime) throws Exception
{
- final Date d = new Date(modtime);
- final Calendar c = new GregorianCalendar();
- c.setTime(d);
- fileInfo.setTimestamp(c);
+ if (fileInfo.isSymbolicLink())
+ {
+ getLinkDestination().getContent().setLastModifiedTime(modtime);
+ }
+ else
+ {
+ final Date d = new Date(modtime);
+ final Calendar c = new GregorianCalendar();
+ c.setTime(d);
+ fileInfo.setTimestamp(c);
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]