You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/03/24 18:40:03 UTC
(commons-io) branch master updated: Only set POSIX permissions if needed
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 3e19ef62a Only set POSIX permissions if needed
3e19ef62a is described below
commit 3e19ef62a07fd94b3febdf2d5c68fc542d56b7c4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 24 14:33:24 2024 -0400
Only set POSIX permissions if needed
Only callers of PathUtils.setPosixPermissions(...) are affected:
- PathUtils.setReadOnly(...)
- PathUtils.deleteFile(..., DeleteOption...)
- CleaningPathVisitor
- DeletingPathVisitor
---
src/changes/changes.xml | 5 +++++
src/main/java/org/apache/commons/io/file/PathUtils.java | 13 ++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ddf8e1c05..91700dd8d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -108,6 +108,11 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" issue="IO-469" due-to="Grigory Fadeev, Kristian Rosenvold, Elliotte Rusty Harold">"Self-suppression not permitted" while using BrokenOutput and BrokenInput streams with try-with-resources.</action>
<action dev="ggregory" type="fix" issue="IO-405" due-to="Elliotte Rusty Harold">Handle zero and negative thresholds #587.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate CountingInputStream in favor of BoundedInputStream.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">PathUtils.setPosixPermissions(...) only sets permissions if needed.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">PathUtils.setReadOnly(...) only sets permissions if needed.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">PathUtils.deleteFile(..., DeleteOption...) only sets permissions if needed.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">CleaningPathVisitor only sets permissions if needed.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">DeletingPathVisitor only sets permissions if needed.</action>
<!-- Add -->
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileName(Path, Function<Path, R>).</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileNameString().</action>
diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java
index 9d3a30f1b..f7b118c5c 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -60,6 +60,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -1518,6 +1519,9 @@ public final class PathUtils {
/**
* Low-level POSIX permission operation to set permissions.
+ * <p>
+ * If the permissions to update are already set, then make no additional calls.
+ * </p>
*
* @param path Set this path's permissions.
* @param addPermissions true to add, false to remove.
@@ -1530,12 +1534,15 @@ public final class PathUtils {
final LinkOption... linkOptions) throws IOException {
if (path != null) {
final Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(path, linkOptions);
+ final Set<PosixFilePermission> newPermissions = new HashSet<>(permissions);
if (addPermissions) {
- permissions.addAll(updatePermissions);
+ newPermissions.addAll(updatePermissions);
} else {
- permissions.removeAll(updatePermissions);
+ newPermissions.removeAll(updatePermissions);
+ }
+ if (!newPermissions.equals(permissions)) {
+ Files.setPosixFilePermissions(path, newPermissions);
}
- Files.setPosixFilePermissions(path, permissions);
return true;
}
return false;