summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDennis Hsieh <yundom@gmail.com>2008-12-29 13:18:07 +0800
committerJean-Baptiste Queru <jbq@google.com>2009-01-21 10:57:08 -0800
commit6a338eb9f99486c6418596992a0de592e2e8d752 (patch)
tree8c61a1afc4835292bfe43a9dd4f54112c0cf4ab8 /src
parent59910f4a9ce953ea74c8db759448f227c96796b3 (diff)
downloadandroid_packages_providers_DownloadProvider-6a338eb9f99486c6418596992a0de592e2e8d752.tar.gz
android_packages_providers_DownloadProvider-6a338eb9f99486c6418596992a0de592e2e8d752.tar.bz2
android_packages_providers_DownloadProvider-6a338eb9f99486c6418596992a0de592e2e8d752.zip
Force sync the downloaded file to the storage after completion.
This will write the downlaoded file to the storage (sdcard in default). It can prevent file corruption if the user removes the sdcard unsafely after a download completes.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 127cc46d..e7872296 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -38,10 +38,12 @@ import android.util.Config;
import android.util.Log;
import java.io.File;
+import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.SyncFailedException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -672,6 +674,19 @@ http_request_loop:
} else if (Downloads.isStatusSuccess(finalStatus)) {
// make sure the file is readable
FileUtils.setPermissions(filename, 0644, -1, -1);
+
+ // Sync to storage after completion
+ try {
+ new FileOutputStream(filename, true).getFD().sync();
+ } catch (FileNotFoundException ex) {
+ Log.w(Constants.TAG, "file " + filename + " not found: " + ex);
+ } catch (SyncFailedException ex) {
+ Log.w(Constants.TAG, "file " + filename + " sync failed: " + ex);
+ } catch (IOException ex) {
+ Log.w(Constants.TAG, "IOException trying to sync " + filename + ": " + ex);
+ } catch (RuntimeException ex) {
+ Log.w(Constants.TAG, "exception while syncing file: ", ex);
+ }
}
}
notifyDownloadCompleted(finalStatus, countRetry, retryAfter, redirectCount,