commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r657169 - in /commons/proper/net/trunk/src: java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java test/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
Date Fri, 16 May 2008 19:07:02 GMT
Author: sebb
Date: Fri May 16 12:07:02 2008
New Revision: 657169

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

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

Modified: commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java?rev=657169&r1=657168&r2=657169&view=diff
==============================================================================
--- commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
(original)
+++ commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
Fri May 16 12:07:02 2008
@@ -57,11 +57,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]* ?
 
 
 
@@ -143,6 +144,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));
@@ -197,9 +202,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/trunk/src/test/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java?rev=657169&r1=657168&r2=657169&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
(original)
+++ commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java
Fri May 16 12:07:02 2008
@@ -160,10 +160,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",
@@ -176,7 +176,7 @@
                      dir.getGroup());
         assertEquals("TRANSLATED",
                      dir.getUser());
-        checkPermisions(dir);
+        checkPermisions(dir, 0705);
     }
 
     /**
@@ -184,7 +184,7 @@
      */
     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",
@@ -197,10 +197,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",
@@ -213,7 +213,7 @@
                      file.getGroup());
         assertEquals("TRANSLATED",
                      file.getUser());
-        checkPermisions(file);
+        checkPermisions(file, 0400);
     }
 
     /**
@@ -257,34 +257,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