Эх сурвалжийг харах

[core] WebHDFS octal permissions should be at most 4 digits

Romain Rigaux 13 жил өмнө
parent
commit
d6b5644

+ 11 - 0
desktop/libs/hadoop/src/hadoop/fs/test_webhdfs.py

@@ -28,6 +28,7 @@ from threading import Thread
 from hadoop import pseudo_hdfs4
 from hadoop.fs.exceptions import WebHdfsException
 from hadoop.fs.hadoopfs import Hdfs
+from hadoop.fs.webhdfs import safe_octal
 
 LOG = logging.getLogger(__name__)
 
@@ -237,3 +238,13 @@ def test_threadedness():
   assert_equals("alpha", fs.user)
   fs.setuser("gamma")
   assert_equals("gamma", fs.user)
+
+def test_safe_octal():
+  assert_equals('0777', safe_octal(0777))
+  assert_equals('0777', safe_octal(00777))
+  assert_equals('1777', safe_octal(01777))
+
+  assert_equals('777', safe_octal('777'))
+  assert_equals('0777', safe_octal('0777'))
+  assert_equals('1777', safe_octal('1777'))
+  assert_equals('1777', safe_octal('01777'))

+ 8 - 2
desktop/libs/hadoop/src/hadoop/fs/webhdfs.py

@@ -569,11 +569,17 @@ def safe_octal(octal_value):
   safe_octal(octal_value) -> octal value in string
 
   This correctly handles octal values specified as a string or as a numeric.
+  Only the 4 rightmost digits are returned (e.g. 01777 becomes 1777).
   """
   try:
-    return oct(octal_value)
+    octal = oct(octal_value)
   except TypeError:
-    return str(octal_value)
+    octal = str(octal_value)
+  if len(octal) > 4:
+    old_octal = octal
+    octal = octal[-4:]
+    LOG.warn('Octal %s was truncated to %s.' % (old_octal, octal))
+  return octal
 
 
 def _get_service_url(hdfs_config):