com.atlassian.bamboo.utils
Class FilePermissionUtil

java.lang.Object
  extended by com.atlassian.bamboo.utils.FilePermissionUtil

public class FilePermissionUtil
extends java.lang.Object

Utility class for changing the file permissions using JDK1.6 File.setWritable and family if available, falling back to executing a chmod command.

The only supported method in this version is setting "600" mode for a file, as seen in preparing a keyfile for ssh command.

See Also:
chmodUserPrivate(java.io.File)

Method Summary
static void chmodUserPrivate(java.io.File file)
          Changes the mode of the file to 600, as required for example by the ssh key files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

chmodUserPrivate

public static void chmodUserPrivate(java.io.File file)
                             throws java.io.IOException,
                                    java.lang.InterruptedException
Changes the mode of the file to 600, as required for example by the ssh key files.

It tries to first invoke Java 1.6 {link}File#setWritable{link} and family using reflection. If it's unavailable, it tries to invoke chmod executable - be aware it will fail on windows unless you have cygwin or similar installed.

Please note that this method is not guaranteed to have done what it's asked - it may fail to change the permission and there is no way for you to know.

Parameters:
file - the file to change permissions on
Throws:
java.io.IOException - when chmod process execution fails - not thrown when using reflection
java.lang.InterruptedException - when process.waitFor(chmod) is interrupted - not thrown when using reflection
java.lang.RuntimeException - when the reflection call on JDK1.6 fails (might be caused by SecurityException)


Copyright © 2011 Atlassian. All Rights Reserved.