Commit 6fd56c1a authored by Petri Hintukainen's avatar Petri Hintukainen

Create cache paths in native code

parent 19529f2b
......@@ -23,7 +23,6 @@
#include "util/attributes.h"
#ifdef _WIN32
BD_PRIVATE int win32_mkdir(const char *dir);
BD_PRIVATE char *win32_get_font_dir(const char *font_file);
#endif
......
......@@ -35,14 +35,6 @@
#include <direct.h>
int win32_mkdir(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
return _wmkdir(wdir);
}
char *win32_get_font_dir(const char *font_file)
{
wchar_t wdir[MAX_PATH];
......
......@@ -23,7 +23,13 @@
#include "file.h"
#include <stdio.h>
#include "util/logging.h"
#include "util/macro.h"
#include "util/strutl.h"
#include <stdio.h> // SEEK_*
#include <string.h> // strchr
int64_t file_size(BD_FILE_H *fp)
{
......@@ -38,3 +44,46 @@ int64_t file_size(BD_FILE_H *fp)
return length;
}
int file_mkdirs(const char *path)
{
int result = 0;
char *dir = str_dup(path);
char *end = dir;
char *p;
/* strip file name */
if (!(end = strrchr(end, DIR_SEP_CHAR))) {
X_FREE(dir);
return -1;
}
*end = 0;
/* tokenize, stop to first existing dir */
while ((p = strrchr(dir, DIR_SEP_CHAR))) {
if (!file_path_exists(dir)) {
break;
}
*p = 0;
}
/* create missing dirs */
p = dir;
while (p < end) {
/* concatenate next non-existing dir */
while (*p) p++;
if (p >= end) break;
*p = DIR_SEP_CHAR;
result = file_mkdir(dir);
if (result < 0) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "Error creating directory %s\n", dir);
break;
}
BD_DEBUG(DBG_FILE, " created directory %s\n", dir);
}
X_FREE(dir);
return result;
}
......@@ -66,6 +66,8 @@ BD_PRIVATE BD_DIR_OPEN dir_open_default(void);
*/
BD_PRIVATE int file_unlink(const char *file);
BD_PRIVATE int file_path_exists(const char *path);
BD_PRIVATE int file_mkdir(const char *dir);
BD_PRIVATE int file_mkdirs(const char *path);
#endif /* FILE_H_ */
......@@ -115,3 +115,17 @@ int file_unlink(const char *file)
{
return remove(file);
}
#include <sys/stat.h>
#include <sys/types.h>
int file_path_exists(const char *path)
{
struct stat s;
return stat(path, &s);
}
int file_mkdir(const char *dir)
{
return mkdir(dir, S_IRWXU);
}
......@@ -133,3 +133,26 @@ int file_unlink(const char *file)
MultiByteToWideChar(CP_UTF8, 0, file, -1, wfile, MAX_PATH);
return _wremove(wfile);
}
int file_path_exists(const char *path)
{
wchar_t wpath[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH);
DWORD dwAttrib = GetFileAttributesW(wpath);
if (dwAttrib != INVALID_FILE_ATTRIBUTES) {
return 0;
}
return -1;
}
int file_mkdir(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
if (!CreateDirectoryW(wdir, NULL))
return -1;
return 0;
}
......@@ -55,6 +55,8 @@ class CacheDir {
SecurityManager sm = System.getSecurityManager();
if (sm != null && sm instanceof BDJSecurityManager) {
((BDJSecurityManager)sm).setCacheRoot(System.getProperty("java.io.tmpdir"));
new File(baseDir).mkdirs();
((BDJSecurityManager)sm).setCacheRoot(baseDir);
}
......
......@@ -68,8 +68,6 @@ class VFSCache {
vfsRoot = vfsRoot + File.separator;
}
vfsRootLength = vfsRoot.length();
new File(cacheRoot + jarDir).mkdirs();
}
/*
......@@ -164,8 +162,6 @@ class VFSCache {
private void copyJarDir(String name) {
/* copy directory from BDMV/JAR/ */
new File(cacheRoot + jarDir + name).mkdirs();
File[] files = new File(vfsRoot + jarDir + name).listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
......@@ -198,8 +194,6 @@ class VFSCache {
protected synchronized File addFont(String fontFile) {
new File(fontRoot + fontDir).mkdirs();
String relPath = fontDir + fontFile;
String dstPath = fontRoot + relPath;
File dstFile = new File(dstPath);
......@@ -279,17 +273,6 @@ class VFSCache {
inAccessFile = false;
}
private void mkdirs_xletCode(String path) {
final File file = new File(path);
AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
file.mkdirs();
return null;
}
});
}
private void accessFileImp(String absPath) {
if (BDFileSystem.nativeFileExists(absPath)) {
......@@ -299,11 +282,8 @@ class VFSCache {
String relPath = absPath.substring(vfsRootLength);
String[] names = org.videolan.Libbluray.listBdFiles(relPath, true);
if (names == null) {
/* this is regular file */
} else {
/* this is directory, make sure it exists */
mkdirs_xletCode(absPath);
if (names != null) {
/* this is directory */
return;
}
......@@ -312,13 +292,6 @@ class VFSCache {
return;
}
/* create the directory */
int sepPos = relPath.lastIndexOf(File.separatorChar);
if (sepPos > 0) {
String absDir = cacheRoot + relPath.substring(0, sepPos);
mkdirs_xletCode(absDir);
}
/* finally, copy the file to cache */
Libbluray.cacheBdRomFile(relPath, cacheRoot + relPath);
}
......
......@@ -419,6 +419,9 @@ int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_pa
return -1;
}
/* make sure path exists */
file_mkdirs(cache_path);
/* output file in local filesystem */
fp_out = file_open_default()(cache_path, "wb");
if (!fp_out) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment