commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r321163 - in /jakarta/commons/proper/vfs/trunk: ./ src/java/org/apache/commons/vfs/ src/java/org/apache/commons/vfs/provider/ftp/ src/java/org/apache/commons/vfs/provider/sftp/
Date Fri, 14 Oct 2005 17:59:56 GMT
Author: imario
Date: Fri Oct 14 10:59:47 2005
New Revision: 321163

URL: http://svn.apache.org/viewcvs?rev=321163&view=rev
Log:
sftp: add filesystem option: setUserDirIsRoot

Modified:
    jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpClientFactory.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystem.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java

Modified: jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt Fri Oct 14 10:59:47 2005
@@ -5,6 +5,7 @@
 
 sftp:
 stip off link file names, though still no link-support for sftp.
+added filesystem option: setUserDirIsRoot
 
 
 2005-09-26  commons-vfs 1.0 RC4

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
Fri Oct 14 10:59:47 2005
@@ -216,6 +216,7 @@
 
 # SFTP Provider
 vfs.provider.sftp/connect.error=Could not connect to SFTP server at "{0}".
+vfs.provider.sftp/change-work-directory.error=Could not change to work directory "{0}".
 vfs.provider.sftp/unknown-permissions.error=File permissions not fetched.
 vfs.provider.sftp/unknown-size.error=File size not fetched.
 vfs.provider.sftp/create-folder.error=Folder creation failed with unknown error.

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpClientFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpClientFactory.java?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpClientFactory.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpClientFactory.java
Fri Oct 14 10:59:47 2005
@@ -100,7 +100,7 @@
                 {
                     if (!client.changeWorkingDirectory(workingDirectory))
                     {
-                        throw new FileSystemException("vfs.provider.ftp/change-work-directory.error",
"/");
+                        throw new FileSystemException("vfs.provider.ftp/change-work-directory.error",
workingDirectory);
                     }
                 }
 

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
Fri Oct 14 10:59:47 2005
@@ -50,12 +50,14 @@
 {
     private final SftpFileSystem fileSystem;
     private SftpATTRS attrs;
+    private final String relPath;
 
     protected SftpFileObject(final FileName name,
-                             final SftpFileSystem fileSystem)
+                             final SftpFileSystem fileSystem) throws FileSystemException
     {
         super(name, fileSystem);
         this.fileSystem = fileSystem;
+        relPath = UriParser.decode(fileSystem.getRootName().getRelativeName(name));
     }
 
     /**
@@ -104,7 +106,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            attrs = channel.stat(getName().getPathDecoded());
+            attrs = channel.stat(relPath);
         }
         catch (final SftpException e)
         {
@@ -132,7 +134,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            channel.mkdir(getName().getPathDecoded());
+            channel.mkdir(relPath);
         }
         finally
         {
@@ -167,7 +169,7 @@
             int newMTime = (int) (modtime / 1000L);
 
             attrs.setACMODTIME(attrs.getATime(), newMTime);
-            channel.setStat(getName().getPathDecoded(), attrs);
+            channel.setStat(relPath, attrs);
         }
         finally
         {
@@ -186,11 +188,11 @@
         {
             if (getType() == FileType.FILE)
             {
-                channel.rm(getName().getPathDecoded());
+                channel.rm(relPath);
             }
             else
             {
-                channel.rmdir(getName().getPathDecoded());
+                channel.rmdir(relPath);
             }
         }
         finally
@@ -207,7 +209,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            channel.rename(getName().getPathDecoded(), newfile.getName().getPathDecoded());
+            channel.rename(relPath, ((SftpFileObject) newfile).relPath);
         }
         finally
         {
@@ -226,7 +228,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            vector = channel.ls(getName().getPathDecoded());
+            vector = channel.ls(relPath);
         }
         finally
         {
@@ -358,7 +360,7 @@
             // TODO - Don't read the entire file into memory.  Use the
             // stream-based methods on ChannelSftp once they work properly
             final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
-            channel.get(getName().getPathDecoded(), outstr);
+            channel.get(relPath, outstr);
             outstr.close();
             return new ByteArrayInputStream(outstr.toByteArray());
 
@@ -406,7 +408,7 @@
             {
                 final ByteArrayOutputStream outstr = (ByteArrayOutputStream) out;
                 channel.put(new ByteArrayInputStream(outstr.toByteArray()),
-                    getName().getPathDecoded());
+                    relPath);
             }
             catch (final SftpException e)
             {

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystem.java?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystem.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystem.java
Fri Oct 14 10:59:47 2005
@@ -18,6 +18,7 @@
 import com.jcraft.jsch.ChannelSftp;
 import com.jcraft.jsch.JSchException;
 import com.jcraft.jsch.Session;
+import com.jcraft.jsch.SftpException;
 import org.apache.commons.vfs.FileName;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystem;
@@ -108,6 +109,20 @@
             {
                 channel = (ChannelSftp) session.openChannel("sftp");
                 channel.connect();
+
+                Boolean userDirIsRoot = SftpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(getFileSystemOptions());
+                String workingDirectory = getRootName().getPath();
+                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
+                {
+                    try
+                    {
+                        channel.cd(workingDirectory);
+                    }
+                    catch (SftpException e)
+                    {
+                        throw new FileSystemException("vfs.provider.sftp/change-work-directory.error",
workingDirectory);
+                    }
+                }
             }
 
             return channel;

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java?rev=321163&r1=321162&r2=321163&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
Fri Oct 14 10:59:47 2005
@@ -16,6 +16,7 @@
 package org.apache.commons.vfs.provider.sftp;
 
 import com.jcraft.jsch.UserInfo;
+import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
 import org.apache.commons.vfs.FileSystemConfigBuilder;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemOptions;
@@ -32,6 +33,8 @@
 {
     private final static SftpFileSystemConfigBuilder builder = new SftpFileSystemConfigBuilder();
 
+    private final static String USER_DIR_IS_ROOT = FTPFileEntryParserFactory.class.getName()
+ ".USER_DIR_IS_ROOT";
+
     public static SftpFileSystemConfigBuilder getInstance()
     {
         return builder;
@@ -158,6 +161,27 @@
     public String getStrictHostKeyChecking(FileSystemOptions opts)
     {
         return (String) getParam(opts, "StrictHostKeyChecking");
+    }
+
+    /**
+     * use user directory as root (do not change to fs root)
+     *
+     * @param opts
+     * @param userDirIsRoot
+     */
+    public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot)
+    {
+        setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
+    }
+
+    /**
+     * @param opts
+     * @return
+     * @see #setUserDirIsRoot
+     */
+    public Boolean getUserDirIsRoot(FileSystemOptions opts)
+    {
+        return (Boolean) getParam(opts, USER_DIR_IS_ROOT);
     }
 
     protected Class getConfigClass()



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message