summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI/src
diff options
context:
space:
mode:
authorBen Kwa <kenobi@google.com>2015-05-05 18:54:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-05 18:54:07 +0000
commitefb70fd8a0a37ddd08356120fb63ff62694eaea0 (patch)
tree649bab12163037f6aef344bcc5305893456f1c1d /packages/DocumentsUI/src
parentd5fb9cac87d65d59e9d2c0fa4242fb6eeb4edf6d (diff)
parentc7a01cfe15b3f485c9f711d83c33d548ee120795 (diff)
downloadframeworks_base-efb70fd8a0a37ddd08356120fb63ff62694eaea0.zip
frameworks_base-efb70fd8a0a37ddd08356120fb63ff62694eaea0.tar.gz
frameworks_base-efb70fd8a0a37ddd08356120fb63ff62694eaea0.tar.bz2
Merge "Cherry pick beefed-up error handling in the CopyService from master. DO NOT MERGE" into mnc-dev
Diffstat (limited to 'packages/DocumentsUI/src')
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/CopyService.java31
1 files changed, 21 insertions, 10 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
index 2e0bece..9dd2b20 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
@@ -449,7 +449,7 @@ public class CopyService extends IntentService {
InputStream src = null;
OutputStream dst = null;
- boolean errorOccurred = false;
+ IOException copyError = null;
try {
srcFile = mSrcClient.openFile(srcUri, "r", canceller);
dstFile = mDstClient.openFile(dstUri, "w", canceller);
@@ -462,24 +462,35 @@ public class CopyService extends IntentService {
dst.write(buffer, 0, len);
makeProgress(len);
}
+
srcFile.checkError();
- dstFile.checkError();
} catch (IOException e) {
- errorOccurred = true;
- Log.e(TAG, "Error while copying " + srcUri.toString(), e);
+ copyError = e;
+ } finally {
+ if (copyError != null) {
+ try {
+ dstFile.closeWithError(copyError.getMessage());
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing destination", e);
+ }
+ }
+ // This also ensures the file descriptors are closed.
+ IoUtils.closeQuietly(src);
+ IoUtils.closeQuietly(dst);
+ }
+
+ if (copyError != null) {
+ // Log errors.
+ Log.e(TAG, "Error while copying " + srcUri.toString(), copyError);
try {
mFailedFiles.add(DocumentInfo.fromUri(getContentResolver(), srcUri));
} catch (FileNotFoundException ignore) {
- Log.w(TAG, "Source file gone: " + srcUri, e);
+ Log.w(TAG, "Source file gone: " + srcUri, copyError);
// The source file is gone.
}
- } finally {
- // This also ensures the file descriptors are closed.
- IoUtils.closeQuietly(src);
- IoUtils.closeQuietly(dst);
}
- if (errorOccurred || mIsCancelled) {
+ if (copyError != null || mIsCancelled) {
// Clean up half-copied files.
canceller.cancel();
try {