From c2a9fe52495566328c231e97232bc31a79efbe13 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 13 Aug 2009 17:26:37 -0700 Subject: [PATCH] Make sure that the android pref folder is always present when queried. BUG: 2053511 --- .../com/android/prefs/AndroidLocation.java | 38 ++++++++++++------- .../com.android.ide.eclipse.adt/.classpath | 4 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/tools/androidprefs/src/com/android/prefs/AndroidLocation.java b/tools/androidprefs/src/com/android/prefs/AndroidLocation.java index cfd9f53b2..446c42656 100644 --- a/tools/androidprefs/src/com/android/prefs/AndroidLocation.java +++ b/tools/androidprefs/src/com/android/prefs/AndroidLocation.java @@ -37,36 +37,46 @@ public final class AndroidLocation { super(string); } } - + private static String sPrefsLocation = null; - + /** * Returns the folder used to store android related files. * @return an OS specific path, terminated by a separator. - * @throws AndroidLocationException + * @throws AndroidLocationException */ public final static String getFolder() throws AndroidLocationException { if (sPrefsLocation == null) { String home = findValidPath("ANDROID_SDK_HOME", "user.home", "HOME"); - + // if the above failed, we throw an exception. if (home == null) { throw new AndroidLocationException( "Unable to get the home directory. Make sure the user.home property is set up"); } else { sPrefsLocation = home + File.separator + ".android" + File.separator; - - // make sure the folder exists! - File f = new File(sPrefsLocation); - if (f.exists() == false) { - f.mkdir(); - } else if (f.isFile()) { - throw new AndroidLocationException(sPrefsLocation + - " is not a directory! This is required to run Android tools."); - } } } + // make sure the folder exists! + File f = new File(sPrefsLocation); + if (f.exists() == false) { + try { + f.mkdir(); + } catch (SecurityException e) { + AndroidLocationException e2 = new AndroidLocationException(String.format( + "Unable to create folder '%1$s'. " + + "This is the path of preference folder expected by the Android tools.", + sPrefsLocation)); + e2.initCause(e); + throw e2; + } + } else if (f.isFile()) { + throw new AndroidLocationException(sPrefsLocation + + " is not a directory! " + + "This is the path of preference folder expected by the Android tools."); + } + return sPrefsLocation; } @@ -92,7 +102,7 @@ public final class AndroidLocation { } } } - + return null; } } diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/.classpath b/tools/eclipse/plugins/com.android.ide.eclipse.adt/.classpath index 7474b7023..568419595 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/.classpath +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/.classpath @@ -3,8 +3,8 @@ - - + +