瀏覽代碼

HDFS-15312. Apply umask when creating directory by WebHDFS (#2096)

Ye Ni 5 年之前
父節點
當前提交
f77bbc2123

+ 29 - 0
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);

+ 29 - 0
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);