From f77bbc2123e3b39117f42e2c9471eb83da98380e Mon Sep 17 00:00:00 2001 From: Ye Ni <141253+NickyYe@users.noreply.github.com> Date: Mon, 6 Jul 2020 19:01:46 -0700 Subject: [PATCH] HDFS-15312. Apply umask when creating directory by WebHDFS (#2096) --- .../src/main/webapps/router/explorer.js | 29 +++++++++++++++++++ .../src/main/webapps/hdfs/explorer.js | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/explorer.js b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/explorer.js index 6917b70d545..490c3934adb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/explorer.js +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/explorer.js @@ -416,9 +416,38 @@ $(this).prop('disabled', true); $(this).button('complete'); + // Get umask from the configuration + var umask, oldUmask, actualUmask; + + $.ajax({'url': '/conf', 'dataType': 'xml', 'async': false}).done( + function(d) { + var $xml = $(d); + $xml.find('property').each(function(idx,v) { + // Current umask config + if ($(v).find('name').text() === 'fs.permissions.umask-mode') { + umask = $(v).find('value').text(); + } + + // Deprecated umask config + if ($(v).find('name').text() === 'dfs.umask') { + oldUmask = $(v).find('value').text(); + } + }); + }); + var url = '/webhdfs/v1' + encode_path(append_path(current_directory, $('#new_directory').val())) + '?op=MKDIRS'; + if (oldUmask) { + actualUmask = 777 - oldUmask; + } else if (umask) { + actualUmask = 777 - umask; + } + + if (actualUmask) { + url = url + '&permission=' + actualUmask; + } + $.ajax(url, { type: 'PUT' } ).done(function(data) { browse_directory(current_directory); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js index cc555670b22..cbf9df99567 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js @@ -416,9 +416,38 @@ $(this).prop('disabled', true); $(this).button('complete'); + // Get umask from the configuration + var umask, oldUmask, actualUmask; + + $.ajax({'url': '/conf', 'dataType': 'xml', 'async': false}).done( + function(d) { + var $xml = $(d); + $xml.find('property').each(function(idx,v) { + // Current umask config + if ($(v).find('name').text() === 'fs.permissions.umask-mode') { + umask = $(v).find('value').text(); + } + + // Deprecated umask config + if ($(v).find('name').text() === 'dfs.umask') { + oldUmask = $(v).find('value').text(); + } + }); + }); + var url = '/webhdfs/v1' + encode_path(append_path(current_directory, $('#new_directory').val())) + '?op=MKDIRS'; + if (oldUmask) { + actualUmask = 777 - oldUmask; + } else if (umask) { + actualUmask = 777 - umask; + } + + if (actualUmask) { + url = url + '&permission=' + actualUmask; + } + $.ajax(url, { type: 'PUT' } ).done(function(data) { browse_directory(current_directory);