[Android] Skip asset copy if file already exists

Geoffrey Métais git at videolan.org
Mon Feb 5 17:18:19 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb  3 15:21:31 2018 +0100| [2df22d79c77edbb0281de34c1ed4c6b3c7f04a04] | committer: Geoffrey Métais

Skip asset copy if file already exists

> https://code.videolan.org/videolan/vlc-android/commit/2df22d79c77edbb0281de34c1ed4c6b3c7f04a04
---

 vlc-android/src/org/videolan/vlc/util/FileUtils.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 3358dcbda..89902bfcd 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -128,8 +128,7 @@ public class FileUtils {
     static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
         try {
             final String[] files = assetManager.list(fromAssetPath);
-            if (files.length == 0)
-                return false;
+            if (files.length == 0) return false;
             new File(toPath).mkdirs();
             boolean res = true;
             for (String file : files)
@@ -150,11 +149,13 @@ public class FileUtils {
 
     private static boolean copyAsset(AssetManager assetManager,
                                      String fromAssetPath, String toPath) {
+        final File destFile = new File(toPath);
+        if (destFile.exists()) return true;
         InputStream in = null;
         OutputStream out = null;
         try {
             in = assetManager.open(fromAssetPath);
-            new File(toPath).createNewFile();
+            destFile.createNewFile();
             out = new FileOutputStream(toPath);
             copyFile(in, out);
             out.flush();



More information about the Android mailing list