This commit is contained in:
Vitor Santos Costa 2018-02-14 14:17:57 +00:00
parent 76d0d54a34
commit e93c01f8e0
6 changed files with 50 additions and 23 deletions

View File

@ -50,12 +50,13 @@ typedef struct {
} vfs_stat;
typedef enum vfs_flags {
VFS_CAN_WRITE = 0x1, /// we can write to files in this space
VFS_CAN_EXEC = 0x2, /// we can execute files in this space
VFS_CAN_SEEK = 0x4, /// we can seek within files in this space
VFS_HAS_PREFIX = 0x8, /// has a prefix that identifies a file in this space
VFS_HAS_SUFFIX = 0x10, /// has a suffix that describes the file.
VFS_HAS_FUNCTION = 0x20 /// has a suffix that describes the file.
VFS_CAN_READ = 0x1, /// we can write to files in this space
VFS_CAN_WRITE = 0x2, /// we can write to files in this space
VFS_CAN_EXEC = 0x4, /// we can execute files in this space
VFS_CAN_SEEK = 0x8, /// we can seek within files in this space
VFS_HAS_PREFIX = 0x10, /// has a prefix that identifies a file in this space
VFS_HAS_SUFFIX = 0x20, /// has a suffix that describes the file.
VFS_HAS_FUNCTION = 0x40 /// has a suffix that describes the file.
} vfs_flags_t;
typedef union {

View File

@ -153,7 +153,7 @@ static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
struct stat bf;
fname += strlen(me->prefix) + 1;
if (stat("/assets", &bf)) {
out->st_mode = me ->vflags ;
out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid;
@ -165,6 +165,8 @@ static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
}
AAsset *a = AAssetManager_open(Yap_assetManager(), fname, AASSET_MODE_UNKNOWN);
// try not to use it as an asset
if (!a)
return false;
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
return true;
@ -173,12 +175,12 @@ static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
static
bool is_dir_a(VFS_t *me, const char *dirName) {
dirName += strlen(me->prefix);
dirName += strlen(me->prefix)+1;
if (dirName[0] == '\0')
dirName = "/";
return true;
// try not to use it as an asset
AAssetDir *d = AAssetManager_openDir(Yap_assetManager(), dirName);
if (d == NULL)
if (d == NULL || AAssetDir_getNextFileName(d) == NULL)
return false;
(AAssetDir_close(d));
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "isdir %s <%p>", dirName, d);
@ -222,7 +224,7 @@ Yap_InitAssetManager(void) {
/* init standard VFS */
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC | VFS_CAN_SEEK |
me->vflags = VFS_CAN_EXEC | VFS_CAN_SEEK | VFS_CAN_READ |
VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** operations */

View File

@ -406,6 +406,33 @@ static Int access_file(USES_REGS1) {
if (!(ares = RepAtom(AtomOfTerm(tname))->StrOfAE))
return FALSE;
}
VFS_t *vfs;
if ((vfs = vfs_owner(ares))) {
bool rc = true;
vfs_stat o;
if (vfs->stat(vfs, ares, &o)) {
if (atmode == AtomExist)
return true;
else if (atmode == AtomExists)
return true;
else if (atmode == AtomWrite)
return o.st_mode & VFS_CAN_WRITE;
else if (atmode == AtomRead)
return o.st_mode & VFS_CAN_READ;
else if (atmode == AtomAppend)
return o.st_mode & VFS_CAN_WRITE;
else if (atmode == AtomCsult)
return o.st_mode & VFS_CAN_READ;
else if (atmode == AtomExecute)
return o.st_mode & VFS_CAN_EXEC;
else {
Yap_Error(DOMAIN_ERROR_IO_MODE, tmode, "access_file/2");
return FALSE;
}
} else {
rc = false;
}
}
#if HAVE_ACCESS
#if _WIN32
{
@ -496,12 +523,7 @@ static Int exists_directory(USES_REGS1) {
if ((vfs = vfs_owner(s))) {
bool rc = true;
void *o;
if ((o=vfs->opendir(vfs, s))) {
rc = true;
vfs->closedir(o);
} else {
rc = false;
}
return vfs->isdir(vfs, s);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return rc;

View File

@ -37,10 +37,11 @@ set_property(GLOBAL
include_directories(. sqlite3)
add_subdirectory(sqlite3)
MY_add_subdirectory(mysql)
MY_add_subdirectory(odbc)
MY_add_subdirectory(postgres)
if (NOT ANDROID)
add_subdirectory(mysql)
add_subdirectory(odbc)
add_subdirectory(postgres)
endif()
add_component(myddas
${MYDDAS_SOURCES}

View File

@ -42,7 +42,7 @@ and_open(struct vfs *me, int sno, const char *name, const char *io_mode) {
GLOBAL_Stream[sno].vfs = me;
GLOBAL_Stream[sno].status = Append_Stream_f | Output_Stream_f;
GLOBAL_Stream[sno].name = Yap_LookupAtom(name);
buff0.clear();
buff0.clear(); // does not work?
return streamerInstance;
}
}

View File

@ -248,12 +248,13 @@ initialize_prolog :-
:- set_prolog_flag(verbose, silent).
%:- set_prolog_flag(verbose_file_search, true ).
%:- yap_flag(write_strings,on).
%:- start_low_level_trace.
:- c_compile( 'preds.yap' ).
:- c_compile( 'modules.yap' ).
:- c_compile( 'grammar.yap' ).
:- ['absf.yap'].
%:- start_low_level_trace.
:- use_module('error.yap').
:- [