You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/11/21 00:55:36 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp FtpFileSystem.java FtpFileObject.java
adammurdoch 2002/11/20 15:55:36
Modified: vfs/src/java/org/apache/commons/vfs/provider/ftp
FtpFileSystem.java FtpFileObject.java
Log:
Use relative paths for locating FTP files, for those FTP server that don't sandbox.
Revision Changes Path
1.10 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
Index: FtpFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FtpFileSystem.java 23 Oct 2002 11:59:41 -0000 1.9
+++ FtpFileSystem.java 20 Nov 2002 23:55:36 -0000 1.10
@@ -151,9 +151,9 @@
/**
* Creates a file object.
*/
- protected FileObject createFile( FileName name )
+ protected FileObject createFile( final FileName name )
throws FileSystemException
{
- return new FtpFileObject( name, this );
+ return new FtpFileObject( name, this, getRootName() );
}
}
1.9 +23 -15 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FtpFileObject.java 25 Oct 2002 03:59:09 -0000 1.8
+++ FtpFileObject.java 20 Nov 2002 23:55:36 -0000 1.9
@@ -76,26 +76,31 @@
private static final FTPFile[] EMPTY_FTP_FILE_ARRAY = {};
private final FtpFileSystem ftpFs;
+ private final String relPath;
// Cached info
private FTPFile fileInfo;
private FTPFile[] children;
- public FtpFileObject( final FileName name, final FtpFileSystem fileSystem )
+ public FtpFileObject( final FileName name,
+ final FtpFileSystem fileSystem,
+ final FileName rootName )
+ throws FileSystemException
{
super( name, fileSystem );
ftpFs = fileSystem;
+ relPath = rootName.getRelativeName( name );
}
/**
* Called by child file objects, to locate their ftp file info.
*/
- private FTPFile getChildFile( String name ) throws Exception
+ private FTPFile getChildFile( final String name ) throws Exception
{
if ( children == null )
{
// List the children of this file
- children = ftpFs.getClient().listFiles( getName().getPath() );
+ children = ftpFs.getClient().listFiles( relPath );
if ( children == null )
{
children = EMPTY_FTP_FILE_ARRAY;
@@ -106,7 +111,7 @@
// TODO - use hash table
for ( int i = 0; i < children.length; i++ )
{
- FTPFile child = children[ i ];
+ final FTPFile child = children[ i ];
if ( child.getName().equals( name ) )
{
// TODO - should be using something else to compare names
@@ -124,8 +129,11 @@
throws Exception
{
// Get the parent folder to find the info for this file
- FtpFileObject parent = (FtpFileObject)getParent();
- fileInfo = parent.getChildFile( getName().getBaseName() );
+ final FtpFileObject parent = (FtpFileObject)getParent();
+ if ( parent != null )
+ {
+ fileInfo = parent.getChildFile( getName().getBaseName() );
+ }
if ( fileInfo == null || !fileInfo.isDirectory() )
{
children = EMPTY_FTP_FILE_ARRAY;
@@ -182,17 +190,17 @@
if ( children == null )
{
// List the children of this file
- children = ftpFs.getClient().listFiles( getName().getPath() );
+ children = ftpFs.getClient().listFiles( relPath );
if ( children == null )
{
children = EMPTY_FTP_FILE_ARRAY;
}
}
- String[] childNames = new String[ children.length ];
+ final String[] childNames = new String[ children.length ];
for ( int i = 0; i < children.length; i++ )
{
- FTPFile child = children[ i ];
+ final FTPFile child = children[ i ];
childNames[ i ] = child.getName();
}
@@ -205,14 +213,14 @@
protected void doDelete() throws Exception
{
final FTPClient ftpClient = ftpFs.getClient();
- boolean ok;
+ final boolean ok;
if ( fileInfo.isDirectory() )
{
- ok = ftpClient.removeDirectory( getName().getPath() );
+ ok = ftpClient.removeDirectory( relPath );
}
else
{
- ok = ftpClient.deleteFile( getName().getPath() );
+ ok = ftpClient.deleteFile( relPath );
}
if ( !ok )
{
@@ -228,7 +236,7 @@
protected void doCreateFolder()
throws Exception
{
- if ( !ftpFs.getClient().makeDirectory( getName().getPath() ) )
+ if ( !ftpFs.getClient().makeDirectory( relPath ) )
{
throw new FileSystemException( "vfs.provider.ftp/create-folder.error", getName() );
}
@@ -248,7 +256,7 @@
*/
protected InputStream doGetInputStream() throws Exception
{
- return ftpFs.getClient().retrieveFileStream( getName().getPath() );
+ return ftpFs.getClient().retrieveFileStream( relPath );
}
/**
@@ -269,7 +277,7 @@
protected OutputStream doGetOutputStream()
throws Exception
{
- return ftpFs.getClient().storeFileStream( getName().getPath() );
+ return ftpFs.getClient().storeFileStream( relPath );
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>