Operation Not Permitted Error.
Previously same code was working without any issues. I hope some recent changes on Mac OS is causing it.
Applet jars are perfectly signed. So I don't think signing is issue.
And I'm trying to create folder under current logged in user directory by using
String userHomePath = System.getProperty("user.home");
**new File(userHomePath +" path ").mkdirs() returns false**
since it doesn't have permissions to create file / folder under it.
Tried the following way to set permission but it fails with same "Operation not permitted error"
//using PosixFilePermission to set file permissions 777
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
//add owners permission
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
//add group permissions
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
//add others permissions
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(Paths.get(path, ""), perms);
If I run the same folder creating code on Main method of a Java class on Mac, it works perfectly. And also If I make runnable jar using export option on eclipse IDE for that applet, it works fine. it was able to create folders in both the cases.
And Also Its works on Windows Operating system.
I googled for setting permission on MAC using Java applets, but I was not able to locate any working solution.
I also tried setting permissions like the below, it also results in the same error "operation not permitted" .
private static void createParent(File directory){
String folderName = directory.getAbsolutePath();
if(directory.exists()){
String [] cmdArray = new String[2];
cmdArray[0] = "chmod -R 4777 "+folderName;
Runtime rt = Runtime.getRuntime();
try {
Process proc = rt.exec(cmdArray);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
folderName = folderName.substring(0,folderName.lastIndexOf(File.separator));
File file = new File(folderName);
createParent(file);
directory.mkdir();
createParent(file);
}
}