Skip to content

Instantly share code, notes, and snippets.

@tresf
Last active February 14, 2020 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tresf/65e69aedd1883770fc2138a19e6166d6 to your computer and use it in GitHub Desktop.
Save tresf/65e69aedd1883770fc2138a19e6166d6 to your computer and use it in GitHub Desktop.
public static void setPermissionsParentally(Path toTraverse, boolean worldWrite) {
Path stepper = toTraverse.toAbsolutePath();
// Assume we shouldn't go higher than top-level (e.g. "/etc")
while(stepper.getParent() != null && !stepper.getRoot().equals(stepper.getParent())) {
log.info("Processing {}", stepper);
File file = stepper.toFile();
file.setReadable(true, false);
file.setExecutable(true, false);
file.setWritable(true, !worldWrite);
if (SystemUtilities.isWindows() && worldWrite) {
WindowsUtilities.setWritable(stepper);
}
stepper = stepper.getParent();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment