mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
Feature flag vfs for fs feature/prevent wasm
This commit is contained in:
@@ -108,6 +108,7 @@ unsafe extern "C" fn register_vfs(name: *const c_char, vfs: *const VfsImpl) -> R
|
||||
/// Get pointers to all the vfs extensions that need to be built in at compile time.
|
||||
/// any other types that are defined in the same extension will not be registered
|
||||
/// until the database file is opened and `register_builtins` is called.
|
||||
#[cfg(feature = "fs")]
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub fn add_builtin_vfs_extensions(
|
||||
api: Option<ExtensionApi>,
|
||||
@@ -158,7 +159,7 @@ pub fn add_builtin_vfs_extensions(
|
||||
fn register_static_vfs_modules(_api: &mut ExtensionApi) {
|
||||
#[cfg(feature = "testvfs")]
|
||||
unsafe {
|
||||
limbo_testvfs::register_extension_static(_api);
|
||||
limbo_ext_tests::register_extension_static(_api);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,9 +207,7 @@ impl Database {
|
||||
#[cfg(feature = "fs")]
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub fn open_new(path: &str, vfs: &str) -> Result<(Arc<dyn IO>, Arc<Database>)> {
|
||||
use ext::add_builtin_vfs_extensions;
|
||||
|
||||
let vfsmods = add_builtin_vfs_extensions(None)?;
|
||||
let vfsmods = ext::add_builtin_vfs_extensions(None)?;
|
||||
let io: Arc<dyn IO> = match vfsmods.iter().find(|v| v.0 == vfs).map(|v| v.1.clone()) {
|
||||
Some(vfs) => vfs,
|
||||
None => match vfs.trim() {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
mod types;
|
||||
mod vfs_modules;
|
||||
pub use limbo_macros::{register_extension, scalar, AggregateDerive, VTabModuleDerive, VfsDerive};
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub use limbo_macros::VfsDerive;
|
||||
pub use limbo_macros::{register_extension, scalar, AggregateDerive, VTabModuleDerive};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
os::raw::{c_char, c_void},
|
||||
};
|
||||
pub use types::{ResultCode, Value, ValueType};
|
||||
use vfs_modules::RegisterVfsFn;
|
||||
pub use vfs_modules::{VfsExtension, VfsFile, VfsFileImpl, VfsImpl};
|
||||
pub use vfs_modules::{RegisterVfsFn, VfsFileImpl, VfsImpl};
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub use vfs_modules::{VfsExtension, VfsFile};
|
||||
|
||||
pub type ExtResult<T> = std::result::Result<T, ResultCode>;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ pub trait VfsExtension: Default + Send + Sync {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub trait VfsFile: Send + Sync {
|
||||
fn lock(&mut self, _exclusive: bool) -> ExtResult<()> {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use lazy_static::lazy_static;
|
||||
use limbo_ext::register_extension;
|
||||
use limbo_ext::{
|
||||
scalar, ExtResult, ResultCode, VTabCursor, VTabKind, VTabModule, VTabModuleDerive, Value,
|
||||
VfsDerive, VfsExtension, VfsFile,
|
||||
register_extension, scalar, ExtResult, ResultCode, VTabCursor, VTabKind, VTabModule,
|
||||
VTabModuleDerive, Value,
|
||||
};
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use limbo_ext::{VfsDerive, VfsExtension, VfsFile};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
@@ -155,6 +156,10 @@ pub struct TestFile {
|
||||
file: File,
|
||||
}
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
pub struct TestFS;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
#[derive(VfsDerive, Default)]
|
||||
pub struct TestFS;
|
||||
|
||||
@@ -165,6 +170,7 @@ fn test_scalar(_args: limbo_ext::Value) -> limbo_ext::Value {
|
||||
limbo_ext::Value::from_integer(42)
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
impl VfsExtension for TestFS {
|
||||
const NAME: &'static str = "testvfs";
|
||||
type File = TestFile;
|
||||
@@ -179,6 +185,7 @@ impl VfsExtension for TestFS {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
impl VfsFile for TestFile {
|
||||
fn read(&mut self, buf: &mut [u8], count: usize, offset: i64) -> ExtResult<i32> {
|
||||
if self.file.seek(SeekFrom::Start(offset as u64)).is_err() {
|
||||
|
||||
Reference in New Issue
Block a user