holdenk commented on code in PR #59061:
URL: https://github.com/apache/spark/pull/59061#discussion_r4429693676


##########
core/src/main/scala/org/apache/spark/util/Utils.scala:
##########
@@ -223,19 +224,52 @@ private[spark] object Utils
     writeByteBufferImpl(bb, out.write)
   }
 
+  // fromString returns a mutable HashSet; wrap it so no future caller can 
mutate the shared set.
+  private val chmod700Perms =
+    Collections.unmodifiableSet(PosixFilePermissions.fromString("rwx------"))
+
   /**
    * JDK equivalent of `chmod 700 file`.
    *
+   * On POSIX filesystems this is a single `chmod` call, which is atomic: 
concurrent calls on
+   * the same path (e.g. Workers sharing a local root dir in local-cluster 
mode) cannot
+   * interleave into a broken permission set, unlike the `File.set*` fallback 
below, each call
+   * of which is a non-atomic stat-then-chmod.
+   *
    * @param file the file whose permissions will be modified
    * @return true if the permissions were successfully changed, false 
otherwise.
    */
   def chmod700(file: File): Boolean = {
-    file.setReadable(false, false) &&
-    file.setReadable(true, true) &&
-    file.setWritable(false, false) &&
-    file.setWritable(true, true) &&
-    file.setExecutable(false, false) &&
-    file.setExecutable(true, true)
+    if (file.getPath.isEmpty) {
+      // The NIO empty path resolves to the process working directory; the 
File.set* sequence
+      // returned false for it, so keep that behavior rather than chmod-ing 
the cwd.
+      return false
+    }
+    try {
+      Files.setPosixFilePermissions(file.toPath, chmod700Perms)
+      true
+    } catch {
+      case _: UnsupportedOperationException =>
+        // Non-POSIX filesystem (e.g. Windows): best-effort, non-atomic 
fallback. Remove all

Review Comment:
   Yeah, maybe we'll just move to `||` since we probably want to try and 
match-ish on windows if we can. WDYT?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to