Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 75A38200CC2 for ; Wed, 21 Jun 2017 02:06:19 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 74BDF160BEF; Wed, 21 Jun 2017 00:06:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BA519160BE1 for ; Wed, 21 Jun 2017 02:06:18 +0200 (CEST) Received: (qmail 48670 invoked by uid 500); 21 Jun 2017 00:06:17 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 48661 invoked by uid 99); 21 Jun 2017 00:06:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jun 2017 00:06:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C0560DFBC6; Wed, 21 Jun 2017 00:06:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yjzhangal@apache.org To: common-commits@hadoop.apache.org Message-Id: <0a6cde830cf14df68b921a7684f2e7a7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-14429. FTPFileSystem#getFsAction always returns FsAction.NONE. (Hongyuan Li via Yongjun Zhang) Date: Wed, 21 Jun 2017 00:06:17 +0000 (UTC) archived-at: Wed, 21 Jun 2017 00:06:19 -0000 Repository: hadoop Updated Branches: refs/heads/trunk 45ff4d38e -> 5157f6c46 HADOOP-14429. FTPFileSystem#getFsAction always returns FsAction.NONE. (Hongyuan Li via Yongjun Zhang) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5157f6c4 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5157f6c4 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5157f6c4 Branch: refs/heads/trunk Commit: 5157f6c46ec342fb650b3c5853061ed1e4a182b6 Parents: 45ff4d3 Author: Yongjun Zhang Authored: Tue Jun 20 16:51:13 2017 -0700 Committer: Yongjun Zhang Committed: Tue Jun 20 16:51:13 2017 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/fs/ftp/FTPFileSystem.java | 9 ++-- .../apache/hadoop/fs/ftp/TestFTPFileSystem.java | 55 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/5157f6c4/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java index 6ce39c1..5f4c8552 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java @@ -415,16 +415,17 @@ public class FTPFileSystem extends FileSystem { return client.removeDirectory(pathName); } - private FsAction getFsAction(int accessGroup, FTPFile ftpFile) { + @VisibleForTesting + FsAction getFsAction(int accessGroup, FTPFile ftpFile) { FsAction action = FsAction.NONE; if (ftpFile.hasPermission(accessGroup, FTPFile.READ_PERMISSION)) { - action.or(FsAction.READ); + action = action.or(FsAction.READ); } if (ftpFile.hasPermission(accessGroup, FTPFile.WRITE_PERMISSION)) { - action.or(FsAction.WRITE); + action = action.or(FsAction.WRITE); } if (ftpFile.hasPermission(accessGroup, FTPFile.EXECUTE_PERMISSION)) { - action.or(FsAction.EXECUTE); + action = action.or(FsAction.EXECUTE); } return action; } http://git-wip-us.apache.org/repos/asf/hadoop/blob/5157f6c4/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java index 0604604..aab52ae 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java @@ -17,14 +17,18 @@ */ package org.apache.hadoop.fs.ftp; +import com.google.common.base.Preconditions; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.permission.FsAction; import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; + import static org.junit.Assert.assertEquals; /** @@ -82,4 +86,55 @@ public class TestFTPFileSystem { client.getDataConnectionMode()); } + + @Test + public void testGetFsAction(){ + FTPFileSystem ftp = new FTPFileSystem(); + int[] accesses = new int[] {FTPFile.USER_ACCESS, FTPFile.GROUP_ACCESS, + FTPFile.WORLD_ACCESS}; + FsAction[] actions = FsAction.values(); + for(int i = 0; i < accesses.length; i++){ + for(int j = 0; j < actions.length; j++){ + enhancedAssertEquals(actions[j], ftp.getFsAction(accesses[i], + getFTPFileOf(accesses[i], actions[j]))); + } + } + } + + private void enhancedAssertEquals(FsAction actionA, FsAction actionB){ + String notNullErrorMessage = "FsAction cannot be null here."; + Preconditions.checkNotNull(actionA, notNullErrorMessage); + Preconditions.checkNotNull(actionB, notNullErrorMessage); + String errorMessageFormat = "expect FsAction is %s, whereas it is %s now."; + String notEqualErrorMessage = String.format(errorMessageFormat, + actionA.name(), actionB.name()); + assertEquals(notEqualErrorMessage, actionA, actionB); + } + + private FTPFile getFTPFileOf(int access, FsAction action) { + boolean check = access == FTPFile.USER_ACCESS || + access == FTPFile.GROUP_ACCESS || + access == FTPFile.WORLD_ACCESS; + String errorFormat = "access must be in [%d,%d,%d], but it is %d now."; + String errorMessage = String.format(errorFormat, FTPFile.USER_ACCESS, + FTPFile.GROUP_ACCESS, FTPFile.WORLD_ACCESS, access); + Preconditions.checkArgument(check, errorMessage); + Preconditions.checkNotNull(action); + FTPFile ftpFile = new FTPFile(); + + if(action.implies(FsAction.READ)){ + ftpFile.setPermission(access, FTPFile.READ_PERMISSION, true); + } + + if(action.implies(FsAction.WRITE)){ + ftpFile.setPermission(access, FTPFile.WRITE_PERMISSION, true); + } + + if(action.implies(FsAction.EXECUTE)){ + ftpFile.setPermission(access, FTPFile.EXECUTE_PERMISSION, true); + } + + return ftpFile; + } + } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org