This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new ac34c984 Add and use FTPFile.setUserPermission(int, boolean).
ac34c984 is described below

commit ac34c984f38156bc03b147d30903173cd01a41c2
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jul 29 11:23:41 2026 -0400

    Add and use FTPFile.setUserPermission(int, boolean).
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/net/ftp/FTPFile.java   | 15 ++++++++-
 .../commons/net/ftp/parser/MLSxEntryParser.java    |  6 ++--
 .../net/ftp/parser/NetwareFTPEntryParser.java      |  4 +--
 .../org/apache/commons/net/ftp/FTPFileTest.java    | 39 ++++++++++++++++++++++
 5 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ede9df44..a63430ac 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Sarankumar Baskar, Matt Pryor, 
Gary Gregory" issue="NET-745">[Javadoc] Improve UnixFTPEntryParser when 
filename with leading space when listing contains a year instead of time (IBM i 
example) (#405).</action>
       <action type="fix" dev="ggregory" due-to="Javid Khan, Gary 
Gregory">Force Gregorian calendar in FTP listing timestamp parsers 
(##406).</action>
       <!-- ADD -->
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use 
FTPFile.setUserPermission(int, boolean).</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
org.apache.commons:commons-parent from 97 to 103.</action>
       <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
commons-io:commons-io from 2.21.0 to 2.22.0.</action>
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPFile.java 
b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
index 42cb6e05..134c6877 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPFile.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
@@ -354,7 +354,7 @@ public class FTPFile implements Serializable {
      * @param access     The access group (one of the {@code _ACCESS} 
constants)
      * @param permission The access permission (one of the {@code _PERMISSION} 
constants)
      * @param value      {@code true} if permission is allowed, {@code false} 
if not.
-     * @throws ArrayIndexOutOfBoundsException if either of the parameters is 
out of range
+     * @throws ArrayIndexOutOfBoundsException if either of the parameters is 
out of range.
      */
     public void setPermission(final int access, final int permission, final 
boolean value) {
         // TODO: only allow permission setting if file is valid
@@ -406,6 +406,19 @@ public class FTPFile implements Serializable {
         this.user = user;
     }
 
+    /**
+     * Sets if the given access group (one of the {@code _ACCESS} constants) 
has the given access permission (one of the {@code _PERMISSION}
+     * constants) to the file.
+     *
+     * @param permission The access permission (one of the {@code _PERMISSION} 
constants)
+     * @param value      {@code true} if permission is allowed, {@code false} 
if not.
+     * @throws ArrayIndexOutOfBoundsException if either of the parameters is 
out of range.
+     * @since 3.14.0
+     */
+    public void setUserPermission(final int permission, final boolean value) {
+        setPermission(USER_ACCESS, permission, value);
+    }
+
     /**
      * Gets a string representation of the FTPFile information. This currently 
mimics the Unix listing format. This method uses the time zone of the Calendar
      * entry, which is the server time zone (if one was provided) otherwise it 
is the local time zone.
diff --git 
a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java 
b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
index a950f5ba..49e4da75 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
@@ -173,17 +173,17 @@ public class MLSxEntryParser extends 
FTPFileEntryParserImpl {
             case 'm': // (dir) can create directory here
             case 'p': // (dir) entries may be deleted
             case 'w': // (files) file may be STORed
-                file.setPermission(FTPFile.USER_ACCESS, 
FTPFile.WRITE_PERMISSION, true);
+                file.setUserPermission(FTPFile.WRITE_PERMISSION, true);
                 break;
             case 'e': // (dir) can change to this dir
             case 'r': // (files) file may be RETRieved
-                file.setPermission(FTPFile.USER_ACCESS, 
FTPFile.READ_PERMISSION, true);
+                file.setUserPermission(FTPFile.READ_PERMISSION, true);
                 break;
             case 'f': // (file) renamable
                 // ?? file.setPermission(FTPFile.USER_ACCESS, 
FTPFile.WRITE_PERMISSION, true);
                 break;
             case 'l': // (dir) can be listed
-                file.setPermission(FTPFile.USER_ACCESS, 
FTPFile.EXECUTE_PERMISSION, true);
+                file.setUserPermission(FTPFile.EXECUTE_PERMISSION, true);
                 break;
             default:
                 break;
diff --git 
a/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java 
b/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
index ba64c488..7d2c644f 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
@@ -145,10 +145,10 @@ public class NetwareFTPEntryParser extends 
ConfigurableFTPFileEntryParserImpl {
             // Now set the permissions (or at least a subset thereof - full 
permissions would probably require
             // subclassing FTPFile and adding extra metainformation there)
             if (attrib.indexOf('R') != -1) {
-                f.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, 
true);
+                f.setUserPermission(FTPFile.READ_PERMISSION, true);
             }
             if (attrib.indexOf('W') != -1) {
-                f.setPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION, 
true);
+                f.setUserPermission(FTPFile.WRITE_PERMISSION, true);
             }
 
             return f;
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java 
b/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java
index a49d09b8..fd5956b7 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java
@@ -65,6 +65,13 @@ class FTPFileTest {
         assertFalse(file.hasPermission(FTPFile.USER_ACCESS, 
FTPFile.WRITE_PERMISSION));
     }
 
+    @Test
+    void testHasPermissionFalse2() {
+        final FTPFile file = new FTPFile();
+        file.setUserPermission(FTPFile.WRITE_PERMISSION, false);
+        assertFalse(file.hasPermission(FTPFile.USER_ACCESS, 
FTPFile.WRITE_PERMISSION));
+    }
+
     @Test
     void testHasPermissionInvalidFile() {
         final FTPFile invalidFile = new FTPFile("LIST");
@@ -78,6 +85,13 @@ class FTPFileTest {
         assertTrue(file.hasPermission(FTPFile.USER_ACCESS, 
FTPFile.READ_PERMISSION));
     }
 
+    @Test
+    void testHasPermissionTrue2() {
+        final FTPFile file = new FTPFile();
+        file.setUserPermission(FTPFile.READ_PERMISSION, true);
+        assertTrue(file.hasPermission(FTPFile.USER_ACCESS, 
FTPFile.READ_PERMISSION));
+    }
+
     @Test
     void testIsDirectory() {
         final FTPFile file = new FTPFile();
@@ -163,6 +177,31 @@ class FTPFileTest {
         assertTrue(formattedString.contains(file.getName()));
     }
 
+    @Test
+    void testToFormattedStringWithTimezone2() {
+        final FTPFile file = new FTPFile();
+        file.setType(FTPFile.FILE_TYPE);
+        file.setSize(32767);
+        file.setUser("Apache");
+        file.setGroup("Apache Group");
+        file.setName("virus.bat");
+        final Calendar timestamp = 
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+        timestamp.set(1969, Calendar.JULY, 16, 13, 32, 0);
+        file.setTimestamp(timestamp);
+        file.setUserPermission(FTPFile.READ_PERMISSION, true);
+        file.setUserPermission(FTPFile.WRITE_PERMISSION, true);
+        file.setUserPermission(FTPFile.EXECUTE_PERMISSION, true);
+        final String formattedString = file.toFormattedString("GMT");
+        assertTrue(formattedString.startsWith("-"));
+        assertTrue(formattedString.startsWith("rwx", 1));
+        assertTrue(formattedString.contains(file.getUser()));
+        assertTrue(formattedString.contains(file.getGroup()));
+        assertTrue(formattedString.contains(String.valueOf(file.getSize())));
+        assertTrue(formattedString.contains("1969-07-16 13:32:00"));
+        assertTrue(formattedString.contains("GMT"));
+        assertTrue(formattedString.contains(file.getName()));
+    }
+
     @Test
     void testToString() {
         final FTPFile file = new FTPFile();

Reply via email to