Class FilePermissionUtil

  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:

Method Summary
static void chmodUserPrivate( 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


public static void chmodUserPrivate( file)
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.

file - the file to change permissions on
Throws: - 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.