Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D0E6617F2E for ; Tue, 22 Sep 2015 19:56:55 +0000 (UTC) Received: (qmail 28362 invoked by uid 500); 22 Sep 2015 19:56:55 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 28321 invoked by uid 500); 22 Sep 2015 19:56:55 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 28312 invoked by uid 99); 22 Sep 2015 19:56:55 -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; Tue, 22 Sep 2015 19:56:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 78027E0362; Tue, 22 Sep 2015 19:56:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: <4186dec4fdc048f5baa59924c7ce013e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-14445 ExportSnapshot does not honor -chmod option Date: Tue, 22 Sep 2015 19:56:55 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/master 487f74172 -> f697d2d31 HBASE-14445 ExportSnapshot does not honor -chmod option Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f697d2d3 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f697d2d3 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f697d2d3 Branch: refs/heads/master Commit: f697d2d312bc04072ccd64c231319e7e571d1aff Parents: 487f741 Author: tedyu Authored: Tue Sep 22 12:56:48 2015 -0700 Committer: tedyu Committed: Tue Sep 22 12:56:48 2015 -0700 ---------------------------------------------------------------------- .../hadoop/hbase/snapshot/ExportSnapshot.java | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/f697d2d3/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java index 5595fc9..0bcbc1e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java @@ -300,8 +300,13 @@ public class ExportSnapshot extends Configured implements Tool { createOutputPath(parent); } outputFs.mkdirs(path); - // override the owner when non-null user/group is specified - outputFs.setOwner(path, filesUser, filesGroup); + if (filesUser != null || filesGroup != null) { + // override the owner when non-null user/group is specified + outputFs.setOwner(path, filesUser, filesGroup); + } + if (filesMode > 0) { + outputFs.setPermission(path, new FsPermission(filesMode)); + } } } @@ -835,6 +840,22 @@ public class ExportSnapshot extends Configured implements Tool { } /** + * Set path permission. + */ + private void setPermission(final FileSystem fs, final Path path, final short filesMode, + final boolean recursive) throws IOException { + if (filesMode > 0) { + FsPermission perm = new FsPermission(filesMode); + if (recursive && fs.isDirectory(path)) { + for (FileStatus child : fs.listStatus(path)) { + setPermission(fs, child.getPath(), filesMode, recursive); + } + } + fs.setPermission(path, perm); + } + } + + /** * Execute the export snapshot by copying the snapshot metadata, hfiles and wals. * @return 0 on success, and != 0 upon failure. */ @@ -960,6 +981,9 @@ public class ExportSnapshot extends Configured implements Tool { if (filesUser != null || filesGroup != null) { setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true); } + if (filesMode > 0) { + setPermission(outputFs, snapshotTmpDir, (short)filesMode, true); + } } catch (IOException e) { throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" + snapshotDir + " to=" + initialOutputSnapshotDir, e);