Last active
June 30, 2021 15:10
-
-
Save cfsimplicity/69fe1fd60fd20e26b337aecd9f9e1cfe to your computer and use it in GitHub Desktop.
Copying Windows file permissions in Lucee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void function copyParentDirectoryPermissions( required string filePath, required string parentDirectoryPath ){ | |
//built-in Java classes with required static methods | |
var Paths = CreateObject( "java", "java.nio.file.Paths" ); | |
var Files = CreateObject( "java", "java.nio.file.Files" ); | |
var aclViewClass = CreateObject( "java", "java.nio.file.attribute.AclFileAttributeView" ).getClass(); | |
//create "path" java objects to work with | |
var parentFolderPath = Paths.get( JavaCast( "string", arguments.parentDirectoryPath ), [] ); | |
var filePath = Paths.get( JavaCast( "string", arguments.filePath ), [] ); | |
//create "views" of the respective ACLs | |
var parentFolderAclView = Files.getFileAttributeView( parentFolderPath, aclViewClass, [] ); | |
var fileAclView = Files.getFileAttributeView( filePath, aclViewClass, [] ); | |
//copy the folder ACL to the file | |
fileAclView.setAcl( parentFolderAclView.getAcl() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment