commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r657240 - in /commons/proper/net/branches/NET_2_0/src: main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
Date Fri, 16 May 2008 22:52:49 GMT
Author: sebb
Date: Fri May 16 15:52:49 2008
New Revision: 657240

URL: http://svn.apache.org/viewvc?rev=657240&view=rev
Log:
NET-214: VMS file permission parsing

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
    commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java?rev=657240&r1=657239&r2=657240&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
Fri May 16 15:52:49 2008
@@ -58,11 +58,12 @@
      * this is the regular expression used by this parser.
      */
     private static final String REGEX =
-        "(.*;[0-9]+)\\s*"
-        + "(\\d+)/\\d+\\s*"
-        +"(\\S+)\\s+(\\S+)\\s+"
-        + "\\[(([0-9$A-Za-z_]+)|([0-9$A-Za-z_]+),([0-9$a-zA-Z_]+))\\]?\\s*"
-        + "\\([a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*\\)";
+        "(.*;[0-9]+)\\s*"                                                   //1  file and
version
+        + "(\\d+)/\\d+\\s*"                                                 //2  size/allocated
+        +"(\\S+)\\s+(\\S+)\\s+"                                             //3+4 date and
time
+        + "\\[(([0-9$A-Za-z_]+)|([0-9$A-Za-z_]+),([0-9$a-zA-Z_]+))\\]?\\s*" //5(6,7,8) owner
+        + "\\([a-zA-Z]*,([a-zA-Z]*),([a-zA-Z]*),([a-zA-Z]*)\\)";            //9,10,11 Permissions
(O,G,W)
+    // TODO - perhaps restrict permissions to [RWED]* ?
 
 
 
@@ -144,6 +145,10 @@
             String size = group(2);
         	String datestr = group(3)+" "+group(4);
             String owner = group(5);
+        	String permissions[] = new String[3];
+        	permissions[0]= group(9);
+            permissions[1]= group(10);
+            permissions[2]= group(11);
             try
             {
                 f.setTimestamp(super.parseTimestamp(datestr));
@@ -198,9 +203,21 @@
             f.setGroup(grp);
             f.setUser(user);
             //set group and owner
-            //Since I don't need the persmissions on this file (RWED), I'll
-            //leave that for further development. 'Cause it will be a bit
-            //elaborate to do it right with VMSes World, Global and so forth.
+
+            //Set file permission. 
+            //VMS has (SYSTEM,OWNER,GROUP,WORLD) users that can contain
+            //R (read) W (write) E (execute) D (delete)
+
+            //iterate for OWNER GROUP WORLD permissions 
+            for (int access = 0; access < 3; access++)
+            {
+                String permission = permissions[access];
+
+                f.setPermission(access, FTPFile.READ_PERMISSION, permission.indexOf('R')>=0);
+                f.setPermission(access, FTPFile.WRITE_PERMISSION, permission.indexOf('W')>=0);
+                f.setPermission(access, FTPFile.EXECUTE_PERMISSION, permission.indexOf('E')>=0);
+            }
+
             return f;
         }
         return null;

Modified: commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java?rev=657240&r1=657239&r2=657240&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
Fri May 16 15:52:49 2008
@@ -28,7 +28,7 @@
 /**
  * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
  * @author <a href="sestegra@free.fr">Stephane ESTE-GRACIAS</a>
- * @version $Id: VMSFTPEntryParserTest.java 437134 2006-08-26 09:36:36Z rwinston $
+ * @version $Id: VMSFTPEntryParserTest.java 657169 2008-05-16 19:07:02Z sebb $
  */
 public class VMSFTPEntryParserTest extends FTPParseTestFramework
 {
@@ -161,10 +161,10 @@
                      dir.getGroup());
         assertEquals("OWNER",
                      dir.getUser());
-        checkPermisions(dir);
+        checkPermisions(dir, 0775);
 
 
-        dir = getParser().parseFTPEntry("DATA.DIR;1               1/9           2-JUN-1998
07:32:04  [TRANSLATED]    (RWED,RWED,RWED,RE)");
+        dir = getParser().parseFTPEntry("DATA.DIR;1               1/9           2-JUN-1998
07:32:04  [TRANSLATED]    (RWED,RWED,,RE)");
         assertTrue("Should be a directory.",
                            dir.isDirectory());
         assertEquals("DATA.DIR",
@@ -177,7 +177,7 @@
                      dir.getGroup());
         assertEquals("TRANSLATED",
                      dir.getUser());
-        checkPermisions(dir);
+        checkPermisions(dir, 0705);
     }
 
     /**
@@ -186,7 +186,7 @@
     @Override
     public void testParseFieldsOnFile() throws Exception
     {
-        FTPFile file = getParser().parseFTPEntry("1-JUN.LIS;1              9/9          
2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,RE)");
+        FTPFile file = getParser().parseFTPEntry("1-JUN.LIS;1              9/9          
2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RW,R)");
         assertTrue("Should be a file.",
                    file.isFile());
         assertEquals("1-JUN.LIS",
@@ -199,10 +199,10 @@
                      file.getGroup());
         assertEquals("OWNER",
                      file.getUser());
-        checkPermisions(file);
+        checkPermisions(file, 0764);
 
 
-        file = getParser().parseFTPEntry("1-JUN.LIS;1              9/9           2-JUN-1998
07:32:04  [TRANSLATED]    (RWED,RWED,RWED,RE)");
+        file = getParser().parseFTPEntry("1-JUN.LIS;1              9/9           2-JUN-1998
07:32:04  [TRANSLATED]    (RWED,RD,,)");
         assertTrue("Should be a file.",
                    file.isFile());
         assertEquals("1-JUN.LIS",
@@ -215,7 +215,7 @@
                      file.getGroup());
         assertEquals("TRANSLATED",
                      file.getUser());
-        checkPermisions(file);
+        checkPermisions(file, 0400);
     }
 
     /**
@@ -262,34 +262,43 @@
      * Verify that the VMS parser does NOT  set the permissions.
      * @param dir
      */
-    private void checkPermisions(FTPFile dir)
+    private void checkPermisions(FTPFile dir, int octalPerm)
     {
+        int permMask = 1<<8;
         assertTrue("Owner should not have read permission.",
-                   !dir.hasPermission(FTPFile.USER_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.USER_ACCESS,
                                       FTPFile.READ_PERMISSION));
+        permMask >>= 1;
         assertTrue("Owner should not have write permission.",
-                   !dir.hasPermission(FTPFile.USER_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.USER_ACCESS,
                                       FTPFile.WRITE_PERMISSION));
+        permMask >>= 1;
         assertTrue("Owner should not have execute permission.",
-                   !dir.hasPermission(FTPFile.USER_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.USER_ACCESS,
                                       FTPFile.EXECUTE_PERMISSION));
+        permMask >>= 1;
         assertTrue("Group should not have read permission.",
-                   !dir.hasPermission(FTPFile.GROUP_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.GROUP_ACCESS,
                                       FTPFile.READ_PERMISSION));
+        permMask >>= 1;
         assertTrue("Group should not have write permission.",
-                   !dir.hasPermission(FTPFile.GROUP_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.GROUP_ACCESS,
                                       FTPFile.WRITE_PERMISSION));
+        permMask >>= 1;
         assertTrue("Group should not have execute permission.",
-                   !dir.hasPermission(FTPFile.GROUP_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.GROUP_ACCESS,
                                       FTPFile.EXECUTE_PERMISSION));
+        permMask >>= 1;
         assertTrue("World should not have read permission.",
-                   !dir.hasPermission(FTPFile.WORLD_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.WORLD_ACCESS,
                                       FTPFile.READ_PERMISSION));
+        permMask >>= 1;
         assertTrue("World should not have write permission.",
-                   !dir.hasPermission(FTPFile.WORLD_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.WORLD_ACCESS,
                                       FTPFile.WRITE_PERMISSION));
+        permMask >>= 1;
         assertTrue("World should not have execute permission.",
-                   !dir.hasPermission(FTPFile.WORLD_ACCESS,
+                ((permMask & octalPerm) != 0) == dir.hasPermission(FTPFile.WORLD_ACCESS,
                                       FTPFile.EXECUTE_PERMISSION));
     }
 



Mime
View raw message