You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/07/27 11:15:20 UTC

[GitHub] [commons-vfs] mvdwalle opened a new pull request, #280: Handle the case where a user does not have any groups

mvdwalle opened a new pull request, #280:
URL: https://github.com/apache/commons-vfs/pull/280

   id -g would return the gid 0
   id -G however would return only a newline resulting in a NumberFormatException


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory commented on a diff in pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory commented on code in PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#discussion_r932140182


##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java:
##########
@@ -260,21 +261,33 @@ public int[] getGroupsIds() throws JSchException, IOException {
                         throw new JSchException(
                                 "Could not get the groups id of the current user (error code: " + code + ")");
                     }
-                    // Retrieve the different groups
-                    final String[] groups = output.toString().trim().split("\\s+");
-
-                    final int[] groupsIds = new int[groups.length];
-                    for (int i = 0; i < groups.length; i++) {
-                        groupsIds[i] = Integer.parseInt(groups[i]);
-                    }
-                    this.groupsIds = groupsIds;
 
+                    this.groupsIds = parseGroupIdOutput(output);
                 }
             }
         }
         return groupsIds;
     }
 
+    /**
+     * Parses the output of the 'id -G' command
+     *
+     * @param output The output from the command
+     * @return the (numeric) group IDs.
+     * @since 2.10

Review Comment:
   You only need `since` tags in new public and protected elements because this is what a user has access to.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory merged pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory merged PR #280:
URL: https://github.com/apache/commons-vfs/pull/280


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory commented on pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#issuecomment-1196652929

   Hi @mvdwalle 
   This needs a unit test otherwise it might become a regression. You can refactor the code with a package private method that contains the conversion logic and call it from a unit test.
   
   Jira: https://issues.apache.org/jira/browse/VFS-822
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory commented on a diff in pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory commented on code in PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#discussion_r932139630


##########
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemGroupsTests.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.sftp;
+
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import org.apache.commons.vfs2.FileSystemOptions;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SftpFileSystemGroupsTests {
+
+    FileSystemOptions options = new FileSystemOptions();

Review Comment:
   Use private and final where you can.



##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java:
##########
@@ -260,21 +261,33 @@ public int[] getGroupsIds() throws JSchException, IOException {
                         throw new JSchException(
                                 "Could not get the groups id of the current user (error code: " + code + ")");
                     }
-                    // Retrieve the different groups
-                    final String[] groups = output.toString().trim().split("\\s+");
-
-                    final int[] groupsIds = new int[groups.length];
-                    for (int i = 0; i < groups.length; i++) {
-                        groupsIds[i] = Integer.parseInt(groups[i]);
-                    }
-                    this.groupsIds = groupsIds;
 
+                    this.groupsIds = parseGroupIdOutput(output);
                 }
             }
         }
         return groupsIds;
     }
 
+    /**
+     * Parses the output of the 'id -G' command
+     *
+     * @param output The output from the command
+     * @return the (numeric) group IDs.
+     * @since 2.10

Review Comment:
   You only need `since` tags in new public and private elements.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory commented on a diff in pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory commented on code in PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#discussion_r932140182


##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java:
##########
@@ -260,21 +261,33 @@ public int[] getGroupsIds() throws JSchException, IOException {
                         throw new JSchException(
                                 "Could not get the groups id of the current user (error code: " + code + ")");
                     }
-                    // Retrieve the different groups
-                    final String[] groups = output.toString().trim().split("\\s+");
-
-                    final int[] groupsIds = new int[groups.length];
-                    for (int i = 0; i < groups.length; i++) {
-                        groupsIds[i] = Integer.parseInt(groups[i]);
-                    }
-                    this.groupsIds = groupsIds;
 
+                    this.groupsIds = parseGroupIdOutput(output);
                 }
             }
         }
         return groupsIds;
     }
 
+    /**
+     * Parses the output of the 'id -G' command
+     *
+     * @param output The output from the command
+     * @return the (numeric) group IDs.
+     * @since 2.10

Review Comment:
   You only need `since` tags in new public and protected elements.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] mvdwalle commented on pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
mvdwalle commented on PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#issuecomment-1196766502

   @garydgregory of course. Was still finding my way around the project a bit. I added a few tests to handle different output.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-vfs] garydgregory commented on a diff in pull request #280: Handle the case where a user does not have any groups

Posted by GitBox <gi...@apache.org>.
garydgregory commented on code in PR #280:
URL: https://github.com/apache/commons-vfs/pull/280#discussion_r932140182


##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java:
##########
@@ -260,21 +261,33 @@ public int[] getGroupsIds() throws JSchException, IOException {
                         throw new JSchException(
                                 "Could not get the groups id of the current user (error code: " + code + ")");
                     }
-                    // Retrieve the different groups
-                    final String[] groups = output.toString().trim().split("\\s+");
-
-                    final int[] groupsIds = new int[groups.length];
-                    for (int i = 0; i < groups.length; i++) {
-                        groupsIds[i] = Integer.parseInt(groups[i]);
-                    }
-                    this.groupsIds = groupsIds;
 
+                    this.groupsIds = parseGroupIdOutput(output);
                 }
             }
         }
         return groupsIds;
     }
 
+    /**
+     * Parses the output of the 'id -G' command
+     *
+     * @param output The output from the command
+     * @return the (numeric) group IDs.
+     * @since 2.10

Review Comment:
   You only need `since` tags in new public and protected elements because this is what a user can access.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org