viirya commented on a change in pull request #26956: [SPARK-30312][SQL] 
Preserve path permission and acl when truncate table
URL: https://github.com/apache/spark/pull/26956#discussion_r363179571
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
 ##########
 @@ -499,8 +499,35 @@ case class TruncateTableCommand(
         val path = new Path(location.get)
         try {
           val fs = path.getFileSystem(hadoopConf)
+          val fileStatus = fs.getFileStatus(path)
+          // Not all fs impl. support these APIs.
+          val optPermission = Try(fileStatus.getPermission())
+          val optAcls = Try(fs.getAclStatus(path).getEntries)
+
           fs.delete(path, true)
+
+          // We should keep original permission/acl of the path.
+          // For owner/group, only super-user can set it, for example on HDFS. 
Because
+          // current user can delete the path, we assume the user/group is 
correct or not an issue.
           fs.mkdirs(path)
+          optPermission.foreach { permission =>
+            Try(fs.setPermission(path, permission)) match {
+              case Failure(e) if e.isInstanceOf[UnsupportedOperationException] 
=>
+                log.warn(s"Can not set original permission $permission back to 
" +
+                  s"the created path: $path. Exception: ${e.getMessage}")
+              case Failure(e) => throw e
 
 Review comment:
   Oh, I see. You meant `UnsupportedOperationException` case. Hmm, `setAcl` 
also has `UnsupportedOperationException` case. I'm not sure if it is possible 
that we can get permission/ACLs, but `setPermission`/`setAcl` throws 
`UnsupportedOperationException`.
   
   Logically, following above reason, it should be safer to fail it too if it 
is `UnsupportedOperationException`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to