[Android] Fix race condition when DB is corrupted

Nicolas Pomepuy git at videolan.org
Wed Sep 4 15:39:11 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Sep  4 07:01:51 2019 +0200| [3da6f0d57e974311d93a2d2031123ce4fdf77d7d] | committer: Nicolas Pomepuy

Fix race condition when DB is corrupted

(cherry picked from commit 8848f1ebe7cc27b518f64e94359369120567bb4b)

> https://code.videolan.org/videolan/vlc-android/commit/3da6f0d57e974311d93a2d2031123ce4fdf77d7d
---

 .../src/org/videolan/medialibrary/Medialibrary.java   | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index ff7a33d9e..5eb03e201 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -63,27 +63,28 @@ public class Medialibrary extends AbstractMedialibrary {
             Log.e(TAG, "Can't load mla: " + ule);
             return ML_INIT_FAILED;
         }
-        //remove old thumbnails directory
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                final File oldDir = new File(extFilesDir + THUMBS_FOLDER_NAME);
-                if (oldDir.isDirectory()) {
+        final File oldDir = new File(extFilesDir + THUMBS_FOLDER_NAME);
+        if (oldDir.isDirectory()) {
+            //remove old thumbnails directory
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+
                     String[] children = oldDir.list();
                     for (String child : children) {
                         new File(oldDir, child).delete();
                     }
                     oldDir.delete();
                 }
-            }
-        }).start();
+            }).start();
+        }
 
         int initCode = nativeInit(dbDirectory + VLC_MEDIA_DB_NAME, extFilesDir + MEDIALIB_FOLDER_NAME);
-        mIsInitiated = initCode != ML_INIT_FAILED;
         if (initCode == ML_INIT_DB_CORRUPTED) {
             Log.e(TAG, "Medialib database is corrupted. Clearing it and try to restore playlists");
             nativeClearDatabase(true);
         }
+        mIsInitiated = initCode != ML_INIT_FAILED;
         return initCode;
     }
 



More information about the Android mailing list