remove file:// protocol from various fileutils methods

This commit is contained in:
Fil Maj 2012-02-16 17:46:16 -08:00
parent 7e4158ce94
commit cd667d6af5

View File

@ -712,6 +712,10 @@ public class FileUtils extends Plugin {
* @throws JSONException * @throws JSONException
*/ */
private JSONObject getParent(String filePath) throws JSONException { private JSONObject getParent(String filePath) throws JSONException {
if (filePath.startsWith("file://")) {
filePath = filePath.substring(7);
}
if (atRootDirectory(filePath)) { if (atRootDirectory(filePath)) {
return getEntry(filePath); return getEntry(filePath);
} }
@ -726,8 +730,13 @@ public class FileUtils extends Plugin {
* @return true if we are at the root, false otherwise. * @return true if we are at the root, false otherwise.
*/ */
private boolean atRootDirectory(String filePath) { private boolean atRootDirectory(String filePath) {
if (filePath.startsWith("file://")) {
filePath = filePath.substring(7);
}
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getPackageName() + "/cache") || if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getPackageName() + "/cache") ||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath())) { filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
filePath.equals("/data/data/" + ctx.getPackageName() + "/")) {
return true; return true;
} }
return false; return false;
@ -742,6 +751,10 @@ public class FileUtils extends Plugin {
* @throws JSONException * @throws JSONException
*/ */
private JSONObject getMetadata(String filePath) throws FileNotFoundException, JSONException { private JSONObject getMetadata(String filePath) throws FileNotFoundException, JSONException {
if (filePath.startsWith("file://")) {
filePath = filePath.substring(7);
}
File file = new File(filePath); File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
@ -766,6 +779,7 @@ public class FileUtils extends Plugin {
if (filePath.startsWith("file://")) { if (filePath.startsWith("file://")) {
filePath = filePath.substring(7); filePath = filePath.substring(7);
} }
File file = new File(filePath); File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
@ -811,7 +825,7 @@ public class FileUtils extends Plugin {
} }
else if (type == PERSISTENT) { else if (type == PERSISTENT) {
fs.put("name", "persistent"); fs.put("name", "persistent");
fs.put("root", "file:///data/data/" + ctx.getPackageName()); fs.put("root", "file:///data/data/" + ctx.getPackageName() + "/");
} }
else { else {
throw new IOException("No filesystem of type requested"); throw new IOException("No filesystem of type requested");