Chromium Code Reviews| Index: base/android/java/src/org/chromium/base/FileUtils.java |
| diff --git a/base/android/java/src/org/chromium/base/FileUtils.java b/base/android/java/src/org/chromium/base/FileUtils.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..75f11a15f67006320a5a481180277cb915984a25 |
| --- /dev/null |
| +++ b/base/android/java/src/org/chromium/base/FileUtils.java |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.base; |
| + |
| +import java.io.File; |
| + |
| +/** |
| + * Helper methods for dealing with Files. |
| + */ |
| +public class FileUtils { |
| + private static final String TAG = "FileUtils"; |
| + |
| + /** |
| + * Delete the given File and (if it's a directory) everything within it. |
| + */ |
| + public static void recursivelyDeleteFile(File currentFile) { |
| + if (currentFile.isDirectory()) { |
|
Yaron
2015/09/22 20:28:08
Assert that we aren't on UI thread?
gone
2015/09/23 11:07:03
Done.
|
| + File[] files = currentFile.listFiles(); |
| + if (files != null) { |
| + for (File file : files) { |
| + recursivelyDeleteFile(file); |
| + } |
| + } |
| + } |
| + |
| + try { |
| + if (!currentFile.delete()) Log.e(TAG, "Failed to delete: " + currentFile); |
| + } catch (SecurityException e) { |
|
Yaron
2015/09/22 20:28:08
Why is this added? Have you seen it?
gone
2015/09/23 11:07:03
Was worried about Android M throwing a fit with th
Yaron
2015/09/24 18:31:01
I don't see it in API docs. Perhaps I'm blind? I g
|
| + Log.e(TAG, "Hit SecurityException when trying to delete: " + currentFile, e); |
| + } |
| + } |
| +} |