commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Sonderegger" <carlos.sondereg...@gmx.net>
Subject VFS SMB and Ant Updates
Date Wed, 02 Jul 2008 19:14:54 GMT
Is there a VFS Developer reading this ?

I noticed you updates on VFS Trunk for SmbFileObject.java 

* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 659785 $ $Date: 2008-05-24 12:32:41 +0200 (Sat, 24 May 2008) $ 

The problematic code change is 
   protected InputStream doGetInputStream() throws Exception 
    { 
        try 
        { 
            return new SmbFileInputStream(file); 
        } 
        catch (SmbException e) 
        { 
            if (e.getErrorCode() == SmbException.ERRbadfile) 
            { 
                throw new FileNotFoundException(getName()); 
            } 
            else if (file.isDirectory()) 
            { 
                throw new FileTypeHasNoContentException(getName()); 
            } 

            throw e; 
        } 
    } 

where in all CIFS Releases I checked, 1.1.16 - 1.1.21c, I cannot find a Method getErrorCode
and SmbException.ERRbadfile.

Against which CIFS Library do you develop ? 



I made some changes in the Ant Task, which allows propagation of FileSystemOptions (Identities
and StrictHostKeyChecking) to the
sftp provider, for src and dest. Also a File Pattern Matcher, using Ant RegExp Implementation,
to select specific Files in the move
command.

If you are interested in those changes, I appended them at the and of the mail. They are against
a copy of trunk for about one year,
also the changed sources are equal to the actual trunk version.

Regards
Carlos



Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
===================================================================
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
(revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons
+++ /vfs/impl/DefaultFileSystemManager.java (working copy)

@@ -594,6 +594,17 @@ 
        } 
  
        /** 
+        * Locates a file by URI. RHU 
+        */ 
+       public FileObject resolveFile(final File baseFile, final String uri, final FileSystemOptions
fileSystemOptions) 
+                       throws FileSystemException 
+       { 
+               final FileObject baseFileObj = getLocalFileProvider().findLocalFile( 
+                               baseFile); 
+               return resolveFile(baseFileObj, uri, fileSystemOptions); 
+       }
+ 
+       /**
         * Resolves a URI, relative to a base file. 
         */ 
        public FileObject resolveFile(final FileObject baseFile, final String uri)
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/provider/http/ThreadLocalHttpConnectionManager.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/provider/http/ThreadLocalHttpConnectionManager.java
(revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/provider/http/ThreadLocalHttpConnectionManager.java
(working copy)

@@ -3,6 +3,7 @@
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpConnection;
 import org.apache.commons.httpclient.HttpConnectionManager; 
+import 
+org.apache.commons.httpclient.params.HttpConnectionManagerParams;
  
 import java.io.IOException; 
 import java.io.InputStream; 
@@ -251,4 +252,10 @@ 
             getLocalHttpConnection().close(); 
         } 
     } 
+    
+    // RHU 
+    public HttpConnectionManagerParams getParams() { 
+               return null; 
+       } 
+    public void setParams(HttpConnectionManagerParams params) {} 
 } 
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
       (revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
       (working copy)

@@ -24,6 +24,7 @@ 
 import org.apache.commons.vfs.util.Messages; 
 import org.apache.tools.ant.BuildException; 
 import org.apache.tools.ant.Project; 
+import org.apache.tools.ant.util.regexp.Regexp; 
  
 import java.util.ArrayList; 
 import java.util.HashSet; 
@@ -62,7 +63,9 @@ 
     private boolean failonerror = true; 
     private String filesList; 
  
-    /** 
+       private Regexp reg = null; 
+ 
+       /** 
      * Sets the destination file. 
      */ 
     public void setDestFile(final String destFile) 
@@ -233,7 +236,7 @@ 
     private void handleFiles() throws Exception 
     { 
         // Locate the destination folder, and make sure it exists 
-        final FileObject destFolder = resolveFile(destDirUrl); 
+        final FileObject destFolder = resolveFile(destDirUrl, destFileSystemOptions); 
         destFolder.createFolder(); 
  
         // Locate the source files, and make sure they exist 
@@ -240,7 +243,7 @@ 
         FileName srcDirName = null; 
         if (srcDirUrl !=null ) 
         { 
-            srcDirName = resolveFile(srcDirUrl).getName(); 
+            srcDirName = resolveFile(srcDirUrl, srcFileSystemOptions).getName(); 
         } 
         final ArrayList srcs = new ArrayList(); 
         for (int i = 0; i < srcFiles.size(); i++) 
@@ -247,7 +250,7 @@ 
         { 
             // Locate the source file, and make sure it exists 
             final SourceInfo src = (SourceInfo) srcFiles.get(i); 
-            final FileObject srcFile = resolveFile(src.file); 
+            final FileObject srcFile = resolveFile(src.file, srcFileSystemOptions); 
             if (!srcFile.exists()) 
             { 
                 final String message = 
@@ -369,7 +372,7 @@ 
             return; 
         } 
         final SourceInfo src = (SourceInfo) srcFiles.get(0); 
-        final FileObject srcFile = resolveFile(src.file); 
+        final FileObject srcFile = resolveFile(src.file, srcFileSystemOptions); 
         if (srcFile.getType() != FileType.FILE) 
         { 
             final String message = 
@@ -379,7 +382,7 @@ 
         } 
  
         // Locate the destination file 
-        final FileObject destFile = resolveFile(destFileUrl); 
+        final FileObject destFile = resolveFile(destFileUrl, destFileSystemOptions); 
  
         // Do the copy 
         handleFile(srcFile, destFile); 
@@ -392,7 +395,15 @@ 
                             final FileObject destFile) 
         throws Exception 
     { 
-        if (!destFile.exists() 
+       if (reg != null) 
+       { 
+               if (!reg.matches(srcFile.getName().getPath())) 
+               { 
+                       return; 
+               } 
+       } 
+ 
+       if (!destFile.exists() 
             || srcFile.getContent().getLastModifiedTime() > destFile.getContent().getLastModifiedTime())

         { 
             // Destination file is out-of-date 
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/DeleteTask.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/DeleteTask.java
     (revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/DeleteTask.java
     (working copy) 
@@ -87,7 +87,7 @@ 
                 while (tok.hasMoreTokens()) 
                 { 
                     String nextFile = tok.nextToken(); 
-                    final FileObject srcFile = resolveFile(srcDirUrl + nextFile); 
+                    final FileObject srcFile = resolveFile(srcDirUrl + nextFile, srcFileSystemOptions);

                     srcFile.delete(Selectors.SELECT_ALL); 
                 } 
             } 
@@ -93,7 +93,7 @@ 
             } 
             else 
             { 
-                final FileObject srcFile = resolveFile(file); 
+                final FileObject srcFile = resolveFile(file, srcFileSystemOptions); 
                 log("Deleting " + srcFile); 
                 srcFile.delete(Selectors.SELECT_ALL); 
             } 
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/MkdirTask.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/MkdirTask.java
      (revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/MkdirTask.java
      (working copy) 
@@ -55,7 +55,7 @@ 
  
         try 
         { 
-            final FileObject dir = resolveFile(dirName); 
+            final FileObject dir = resolveFile(dirName, srcFileSystemOptions); 
             final String message = Messages.getString("vfs.tasks/mkdir.create-folder.info",
dir); 
             log(message); 
             dir.createFolder(); 
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/ShowFileTask.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/ShowFileTask.java
   (revision 565695)

+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/ShowFileTask.java
   (working copy) 
@@ -71,7 +71,7 @@ 
     { 
         try 
         { 
-            final FileObject file = resolveFile(url); 
+            final FileObject file = resolveFile(url, srcFileSystemOptions); 
             log("Details of " + file.getName().getURI()); 
             showFile(file, INDENT); 
         } 
Index: U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/VfsTask.java

=================================================================== 
--- U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/VfsTask.java
(revision 565695) 
+++ U:/dev/java/app/vfs-trunk_used/core/src/main/java/org/apache/commons/vfs/tasks/VfsTask.java
(working copy) 
@@ -16,11 +16,16 @@ 
  */ 
 package org.apache.commons.vfs.tasks; 
  
+import java.io.File; 
+ 
 import org.apache.commons.logging.Log; 
 import org.apache.commons.vfs.FileObject; 
 import org.apache.commons.vfs.FileSystemException; 
+import org.apache.commons.vfs.FileSystemOptions; 
 import org.apache.commons.vfs.impl.StandardFileSystemManager; 
+import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder; 
 import org.apache.tools.ant.BuildEvent; 
+import org.apache.tools.ant.BuildException; 
 import org.apache.tools.ant.Project; 
 import org.apache.tools.ant.SubBuildListener; 
 import org.apache.tools.ant.Task; 
@@ -38,6 +43,10 @@ 
 { 
     private static StandardFileSystemManager manager; 
  
+       protected static FileSystemOptions srcFileSystemOptions = new FileSystemOptions();

+ 
+       protected static FileSystemOptions destFileSystemOptions = new FileSystemOptions();

+ 
     /** 
      * Resolves a URI to a file, relative to the project's base directory. 
      * 
@@ -43,7 +52,8 @@ 
      * 
      * @param uri The URI to resolve. 
      */ 
-    protected FileObject resolveFile(final String uri) 
+    protected FileObject resolveFile(final String uri, 
+                       FileSystemOptions fileSystemOptions) 
         throws FileSystemException 
     { 
         if (manager == null) 
@@ -53,7 +63,8 @@ 
             manager.init(); 
             getProject().addBuildListener(new CloseListener()); 
         } 
-        return manager.resolveFile(getProject().getBaseDir(), uri); 
+        return manager.resolveFile(getProject().getBaseDir(), uri, 
+                               fileSystemOptions); 
     } 
  
     /** 
@@ -68,7 +79,73 @@ 
         } 
     } 
  
-    /** 
+       File[] addToArray(File[] array, File s) { 
+               int len = (array == null) ? 0 : array.length; 
+ 
+               File[] ans = new File[len + 1]; 
+               if (len > 0) { 
+                       System.arraycopy(array, 0, ans, 0, len); 
+               } 
+               ans[len] = s; 
+               return ans; 
+       } 
+ 
+       private void setSftpStrictHostKeyChecking(FileSystemOptions fileSystemOptions, final
String option) { 
+               try { 
+                       SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(

+                                       fileSystemOptions, option); 
+               } catch (FileSystemException e) { 
+                       throw new BuildException(e); 
+               } 
+               
+       } 
+ 
+       /** 
+        * Sets the src Sftp StrictHostKeyChecking. 
+        */ 
+       public void setSrcSftpStrictHostKeyChecking(final String option) { 
+               
+               setSftpStrictHostKeyChecking(srcFileSystemOptions, option); 
+       } 
+ 
+       /** 
+        * Sets the dest Sftp StrictHostKeyChecking. 
+        */ 
+       public void setDestSftpStrictHostKeyChecking(final String option) { 
+               
+               setSftpStrictHostKeyChecking(destFileSystemOptions, option); 
+       } 
+ 
+       
+       /** 
+        * Sets the src Sftp StrictHostKeyChecking. 
+        */ 
+       private void setSftpIdentities(FileSystemOptions fileSystemOptions, final String identityFilename)
{ 
+               try { 
+                       File identity = new File(identityFilename); 
+ 
+                       File[] identities = SftpFileSystemConfigBuilder.getInstance() 
+                                       .getIdentities(fileSystemOptions); 
+ 
+                       identities = addToArray(identities, identity); 
+ 
+                       SftpFileSystemConfigBuilder.getInstance().setIdentities( 
+                                       fileSystemOptions, identities); 
+ 
+               } catch (FileSystemException e) { 
+                       throw new BuildException(e); 
+               } 
+       } 
+ 
+       public void setSrcSftpIdentities(final String identityFilename) { 
+               setSftpIdentities(srcFileSystemOptions, identityFilename); 
+       } 
+ 
+       public void setDestSftpIdentities(final String identityFilename) { 
+               setSftpIdentities(destFileSystemOptions, identityFilename); 
+       } 
+ 
+       /** 
      * Closes the VFS manager when the project finishes. 
      */ 
     private class CloseListener 


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


Mime
View raw message