Skip to content

Instantly share code, notes, and snippets.

@cfsimplicity
Last active June 30, 2021 15:10
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 cfsimplicity/69fe1fd60fd20e26b337aecd9f9e1cfe to your computer and use it in GitHub Desktop.
Save cfsimplicity/69fe1fd60fd20e26b337aecd9f9e1cfe to your computer and use it in GitHub Desktop.
Copying Windows file permissions in Lucee
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