核心功能: - ✅ Categories/Series双视图管理(category_view.rs + import_markdown.rs) - ✅ FUSE Multi-Volume支持(tree_type参数) - ✅ SSH/SFTP/SCP/rsync协议完整实现(4042行) - ✅ NFS/SMB Module Phase 1-3完成 - ✅ Archive Module Phase 1-4完成(2916行) - ✅ Download Center API完整实现 - ✅ S3兼容API实现(560行) Git配置修正: - ✅ 删除错误origin(gitea.momentry.ddns.net) - ✅ 删除m5max128(指向机器名) - ✅ 设置origin = m5max128gitea.momentry.ddns.net/admin/markbase - ✅ 设置m4minigitea = m4minigitea.momentry.ddns.net/warren/markbase 数据清理: - ✅ 删除38个临时SQLite(保留accusys.sqlite、demo.sqlite) - ✅ 删除.bak、test_*.bin、调试脚本等临时文件 - ✅ 删除临时目录(build/、download files/、raid_test/等) - ✅ 更新.gitignore排除临时文件 架构优化: - 52个文件修改,2434行新增,4739行删除 - Workspace成员整合(16个crate) - 数据库状态:accusys.sqlite保留(主demo测试) 远程同步: - ✅ 准备推送到m5max128gitea(远程Gitea) - ✅ 准备推送到m4minigitea(本地Gitea)
127 lines
5.2 KiB
Swift
127 lines
5.2 KiB
Swift
import Foundation
|
|
import FSKit
|
|
|
|
@available(macOS 15.4, *)
|
|
public class MarkBaseFSModule: NSObject, FSUnaryFileSystemOperations, @unchecked Sendable {
|
|
|
|
private var rustFS: NSObject?
|
|
private var rustHandle: UnsafeMutableRawPointer?
|
|
|
|
public required override init() {
|
|
super.init()
|
|
// Don't load dylib here - will be loaded in didFinishLoading()
|
|
}
|
|
|
|
deinit {
|
|
if let handle = rustHandle {
|
|
Darwin.dlclose(handle)
|
|
}
|
|
}
|
|
|
|
// MARK: - FSUnaryFileSystemOperations
|
|
|
|
public func probeResource(resource: FSResource, replyHandler: @escaping (FSProbeResult?, Error?) -> Void) {
|
|
print("MarkBaseFSModule: probeResource() called")
|
|
|
|
guard let rustFS = rustFS else {
|
|
print("MarkBaseFSModule: Rust FS not loaded, returning error")
|
|
replyHandler(nil, NSError(domain: "MarkBaseFS", code: -1, userInfo: [NSLocalizedDescriptionKey: "Rust FS not loaded"]))
|
|
return
|
|
}
|
|
|
|
print("MarkBaseFSModule: Rust FS available, but ObjC interop limitation - cannot forward calls")
|
|
replyHandler(nil, NSError(domain: "MarkBaseFS", code: -3, userInfo: [NSLocalizedDescriptionKey: "Swift ObjC interop limitation"]))
|
|
}
|
|
|
|
public func loadResource(resource: FSResource, options: FSTaskOptions, replyHandler: @escaping (FSVolume?, Error?) -> Void) {
|
|
print("MarkBaseFSModule: loadResource() called")
|
|
replyHandler(nil, NSError(domain: "MarkBaseFS", code: -1, userInfo: [NSLocalizedDescriptionKey: "Swift ObjC interop limitation"]))
|
|
}
|
|
|
|
public func unloadResource(resource: FSResource, options: FSTaskOptions, replyHandler: @escaping (Error?) -> Void) {
|
|
print("MarkBaseFSModule: unloadResource() called")
|
|
replyHandler(NSError(domain: "MarkBaseFS", code: -1, userInfo: [NSLocalizedDescriptionKey: "Swift ObjC interop limitation"]))
|
|
}
|
|
|
|
public func didFinishLoading() {
|
|
print("MarkBaseFSModule: didFinishLoading() called")
|
|
print(" - Module loaded by FSKit daemon")
|
|
|
|
// Load Rust dylib and call registration functions
|
|
loadRustDylibAndRegister()
|
|
|
|
print(" - Rust FS instance: \(rustFS != nil ? "available" : "not available")")
|
|
}
|
|
|
|
private func loadRustDylibAndRegister() {
|
|
// 1. Get Extension bundle path
|
|
let bundlePath = Bundle.main.bundlePath
|
|
let dylibPath = "\(bundlePath)/Frameworks/libmarkbase_fskit.dylib"
|
|
|
|
print("MarkBaseFSModule: Loading Rust dylib from: \(dylibPath)")
|
|
|
|
// 2. dlopen Rust dylib
|
|
rustHandle = Darwin.dlopen(dylibPath, RTLD_NOW | RTLD_LOCAL)
|
|
guard rustHandle != nil else {
|
|
if let error = Darwin.dlerror() {
|
|
let errorString = String(cString: error)
|
|
print("MarkBaseFSModule: Failed to load Rust dylib: \(errorString)")
|
|
} else {
|
|
print("MarkBaseFSModule: Failed to load Rust dylib (unknown error)")
|
|
}
|
|
return
|
|
}
|
|
|
|
print("MarkBaseFSModule: Rust dylib loaded successfully")
|
|
|
|
// 3. Call registration functions to register ObjC classes
|
|
let registerFuncs = [
|
|
"__REGISTER_CLASS_MarkBaseFS",
|
|
"__REGISTER_CLASS_MarkBaseFSItem",
|
|
"__REGISTER_CLASS_MarkBaseVolume",
|
|
]
|
|
|
|
for funcName in registerFuncs {
|
|
if let registerFunc = Darwin.dlsym(rustHandle!, funcName) {
|
|
print("MarkBaseFSModule: Calling registration function: \(funcName)")
|
|
let registerFuncPtr = unsafeBitCast(registerFunc, to: (@convention(c) () -> Void).self)
|
|
registerFuncPtr()
|
|
} else {
|
|
print("MarkBaseFSModule: Registration function not found: \(funcName)")
|
|
}
|
|
}
|
|
|
|
print("MarkBaseFSModule: All ObjC classes registered")
|
|
|
|
// 4. Now create instance of Rust's MarkBaseFS class
|
|
let className = "MarkBaseFS" as NSString
|
|
if let utf8String = className.utf8String {
|
|
if let fsClass = objc_lookUpClass(utf8String) {
|
|
print("MarkBaseFSModule: Class obtained: \(className)")
|
|
|
|
// Create instance
|
|
if let instance = (fsClass as? NSObject.Type)?.init() {
|
|
rustFS = instance
|
|
print("MarkBaseFSModule: Rust FSKit instance created successfully")
|
|
|
|
// Verify methods
|
|
let selector1 = NSSelectorFromString("probeResource:replyHandler:")
|
|
let selector2 = NSSelectorFromString("loadResource:options:replyHandler:")
|
|
|
|
print(" - responds to probeResource: \(rustFS!.responds(to: selector1))")
|
|
print(" - responds to loadResource: \(rustFS!.responds(to: selector2))")
|
|
} else {
|
|
print("MarkBaseFSModule: Failed to create instance")
|
|
}
|
|
} else {
|
|
print("MarkBaseFSModule: Class not found after registration")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Helper function
|
|
|
|
private func objc_lookUpClass(_ name: UnsafePointer<CChar>) -> AnyClass? {
|
|
return objc_getClass(name) as? AnyClass
|
|
} |