[libbluray-devel] BD-J Cache: bypass VFS

hpi1 git at videolan.org
Thu Feb 19 19:12:15 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Feb 19 19:51:47 2015 +0200| [7fc6531ea0873fcfe3359f894ef5188a233c1c4d] | committer: hpi1

BD-J Cache: bypass VFS

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=7fc6531ea0873fcfe3359f894ef5188a233c1c4d
---

 src/libbluray/bdj/java/java/io/BDFileSystem.java  |   15 +++++++++++++++
 src/libbluray/bdj/java/org/videolan/CacheDir.java |   15 +++++++++------
 src/libbluray/bdj/java/org/videolan/VFSCache.java |    8 ++++----
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 3107330..9800022 100644
--- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
+++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
@@ -64,6 +64,21 @@ public abstract class BDFileSystem extends FileSystem {
         }
     }
 
+    public static String[] nativeList(File f) {
+        return getFileSystem().list(f);
+    }
+
+    public static boolean nativeFileExists(String path) {
+        return getFileSystem().getBooleanAttributes(new File(path)) != 0;
+    }
+
+    public static boolean nativeDelete(File f) {
+        return getFileSystem().delete(f);
+    }
+
+    /*
+     */
+
     public BDFileSystem(FileSystem fs) {
         this.fs = fs;
     }
diff --git a/src/libbluray/bdj/java/org/videolan/CacheDir.java b/src/libbluray/bdj/java/org/videolan/CacheDir.java
index 11b8f9e..a21d793 100644
--- a/src/libbluray/bdj/java/org/videolan/CacheDir.java
+++ b/src/libbluray/bdj/java/org/videolan/CacheDir.java
@@ -22,6 +22,8 @@ package org.videolan;
 import java.io.File;
 import java.io.IOException;
 
+import java.io.BDFileSystem;
+
 class CacheDir {
 
     private static LockFile lockCache(String path) {
@@ -29,10 +31,11 @@ class CacheDir {
     }
 
     private static void cleanupCache() {
-        File[] files = new File(baseDir).listFiles();
+        File baseDirFile = new File(baseDir);
+        String[] files = BDFileSystem.nativeList(baseDirFile);
         if (files != null) {
             for (int i = 0; i < files.length; i++) {
-                File dir = files[i];
+                File dir = new File(baseDirFile, files[i]);
                 if (dir.isDirectory()) {
                     LockFile lock = lockCache(dir.getPath());
                     if (lock != null) {
@@ -84,21 +87,21 @@ class CacheDir {
     }
 
     private static void removeImpl(File dir) {
-        File[] files = dir.listFiles();
+        String[] files = BDFileSystem.nativeList(dir);
         if (files != null) {
         for (int i = 0; i < files.length; i++) {
-            File file = files[i];
+            File file = new File(dir, files[i]);
             if (file.isDirectory()) {
                 removeImpl(file);
             } else {
-                if (!file.delete()) {
+                if (!BDFileSystem.nativeDelete(file)) {
                     logger.info("Error removing " + file.getPath());
                 }
             }
         }
         }
 
-        if (!dir.delete()) {
+        if (!BDFileSystem.nativeDelete(dir)) {
             logger.error("Error removing " + dir.getPath());
         }
     }
diff --git a/src/libbluray/bdj/java/org/videolan/VFSCache.java b/src/libbluray/bdj/java/org/videolan/VFSCache.java
index 00db461..6c57974 100644
--- a/src/libbluray/bdj/java/org/videolan/VFSCache.java
+++ b/src/libbluray/bdj/java/org/videolan/VFSCache.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import java.io.BDFileSystem;
 import org.videolan.bdjo.AppCache;
 
 class VFSCache {
@@ -139,9 +140,8 @@ class VFSCache {
 
         String relPath = jarDir + name;
         String dstPath = cacheRoot + relPath;
-        File   dstFile = new File(dstPath);
 
-        if (dstFile.exists()) {
+        if (BDFileSystem.nativeFileExists(dstPath)) {
             //logger.info(dstPath + " already cached");
             return;
         }
@@ -194,7 +194,7 @@ class VFSCache {
         String dstPath = fontRoot + relPath;
         File dstFile = new File(dstPath);
 
-        if (dstFile.exists()) {
+        if (BDFileSystem.nativeFileExists(dstPath)) {
             //logger.info(dstPath + " already cached");
             return dstFile;
         }
@@ -263,7 +263,7 @@ class VFSCache {
         }
 
         String cachePath = cacheRoot + absPath.substring(vfsRootLength);
-        if (!new File(cachePath).exists()) {
+        if (!BDFileSystem.nativeFileExists(cachePath)) {
             //logger.info(cachePath + " not in VFS cache");
             return absPath;
         }



More information about the libbluray-devel mailing list