diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2014-01-30 15:01:22 -0800 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2014-02-06 09:47:38 -0800 |
| commit | ebf8ad5d91b22eb4359c75711a5b70ddcce0723d (patch) | |
| tree | 8e4664b788a5de2a64c2b8764da9727c3305b9ed /core/java/android/os/FileUtils.java | |
| parent | b341a24b2adbb67cdc34ade0a19570ee37f0cb82 (diff) | |
Update DrmOutputStream to use raw FileDescriptor.
This allows DownloadManager to use FDs, paving the way for downloading
directly to content:// Uris.
Also return flag indicating if deleteOlderFiles() actually deleted
anything. Update tests to verify.
Bug: 5287571
Change-Id: I2579e5e2113f31b2860d7b021bd61c91b6310963
Diffstat (limited to 'core/java/android/os/FileUtils.java')
| -rw-r--r-- | core/java/android/os/FileUtils.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java index 15a154aba257..dc18dee31f3d 100644 --- a/core/java/android/os/FileUtils.java +++ b/core/java/android/os/FileUtils.java @@ -326,14 +326,15 @@ public class FileUtils { * * @param minCount Always keep at least this many files. * @param minAge Always keep files younger than this age. + * @return if any files were deleted. */ - public static void deleteOlderFiles(File dir, int minCount, long minAge) { + public static boolean deleteOlderFiles(File dir, int minCount, long minAge) { if (minCount < 0 || minAge < 0) { throw new IllegalArgumentException("Constraints must be positive or 0"); } final File[] files = dir.listFiles(); - if (files == null) return; + if (files == null) return false; // Sort with newest files first Arrays.sort(files, new Comparator<File>() { @@ -344,16 +345,20 @@ public class FileUtils { }); // Keep at least minCount files + boolean deleted = false; for (int i = minCount; i < files.length; i++) { final File file = files[i]; // Keep files newer than minAge final long age = System.currentTimeMillis() - file.lastModified(); if (age > minAge) { - Log.d(TAG, "Deleting old file " + file); - file.delete(); + if (file.delete()) { + Log.d(TAG, "Deleted old file " + file); + deleted = true; + } } } + return deleted; } /** |
