Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Unified Diff: base/android/java/src/org/chromium/base/ResourceExtractor.java

Issue 2847923004: Android: ResourceExtractor.java: Extract files atomically (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/ResourceExtractor.java
diff --git a/base/android/java/src/org/chromium/base/ResourceExtractor.java b/base/android/java/src/org/chromium/base/ResourceExtractor.java
index c1d18560f8e2da038a90c0a680f79d17ef039319..ce30ba67d676ea7c00fd47789fdc880603065ff4 100644
--- a/base/android/java/src/org/chromium/base/ResourceExtractor.java
+++ b/base/android/java/src/org/chromium/base/ResourceExtractor.java
@@ -44,8 +44,9 @@ public class ResourceExtractor {
private void extractResourceHelper(InputStream is, File outFile, byte[] buffer)
throws IOException {
OutputStream os = null;
+ File tmpOutputFile = new File(outFile.getPath() + ".tmp");
try {
- os = new FileOutputStream(outFile);
+ os = new FileOutputStream(tmpOutputFile);
Log.i(TAG, "Extracting resource %s", outFile);
int count = 0;
@@ -53,15 +54,11 @@ public class ResourceExtractor {
os.write(buffer, 0, count);
}
} finally {
- try {
- if (os != null) {
- os.close();
- }
- } finally {
- if (is != null) {
- is.close();
- }
- }
+ StreamUtil.closeQuietly(os);
+ StreamUtil.closeQuietly(is);
+ }
+ if (!tmpOutputFile.renameTo(outFile)) {
+ throw new IOException();
}
}
@@ -88,7 +85,7 @@ public class ResourceExtractor {
}
TraceEvent.begin("WalkAssets");
- byte[] buffer = new byte[BUFFER_SIZE];
+ byte[] buffer = null;
try {
for (String assetName : mAssetsToExtract) {
File output = new File(outputDir, assetName);
@@ -98,6 +95,9 @@ public class ResourceExtractor {
continue;
}
TraceEvent.begin("ExtractResource");
+ if (buffer == null) {
+ buffer = new byte[BUFFER_SIZE];
+ }
InputStream inputStream =
ContextUtils.getApplicationContext().getAssets().open(assetName);
try {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698