[Android] Fix race condition when DB is corrupted
Nicolas Pomepuy
git at videolan.org
Wed Sep 4 13:54:45 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Sep 4 07:01:51 2019 +0200| [8848f1ebe7cc27b518f64e94359369120567bb4b] | committer: Nicolas Pomepuy
Fix race condition when DB is corrupted
> https://code.videolan.org/videolan/vlc-android/commit/8848f1ebe7cc27b518f64e94359369120567bb4b
---
.../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