mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
File open fixes.
This commit is contained in:
11
conn.go
11
conn.go
@@ -241,6 +241,17 @@ func getString(memory api.Memory, ptr, maxlen uint32) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Conn) getFile(f *os.File) uint32 {
|
||||
for i := range c.files {
|
||||
if c.files[i] == nil {
|
||||
c.files[i] = f
|
||||
return uint32(i)
|
||||
}
|
||||
}
|
||||
c.files = append(c.files, f)
|
||||
return uint32(len(c.files) - 1)
|
||||
}
|
||||
|
||||
type connContext struct{}
|
||||
|
||||
const ptrSize = 4
|
||||
|
||||
@@ -20,7 +20,7 @@ int go_full_pathname(sqlite3_vfs *, const char *zName, int nOut, char *zOut);
|
||||
|
||||
struct go_file {
|
||||
sqlite3_file base;
|
||||
int fd;
|
||||
int id;
|
||||
};
|
||||
|
||||
int go_close(sqlite3_file *);
|
||||
@@ -59,8 +59,9 @@ static int go_open_c(sqlite3_vfs *vfs, sqlite3_filename zName,
|
||||
.xSectorSize = no_sector_size,
|
||||
.xDeviceCharacteristics = no_device_characteristics,
|
||||
};
|
||||
file->pMethods = &go_io;
|
||||
return go_open(vfs, zName, file, flags, pOutFlags);
|
||||
int rc = go_open(vfs, zName, file, flags, pOutFlags);
|
||||
file->pMethods = rc == SQLITE_OK ? &go_io : NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int sqlite3_os_init() {
|
||||
|
||||
18
vfs.go
18
vfs.go
@@ -186,19 +186,13 @@ func vfsOpen(ctx context.Context, mod api.Module, vfs, zName, file, flags, pOutF
|
||||
return uint32(CANTOPEN)
|
||||
}
|
||||
|
||||
var id int
|
||||
for i := range c.files {
|
||||
if c.files[i] == nil {
|
||||
id = i
|
||||
c.files[i] = f
|
||||
goto found
|
||||
}
|
||||
if ok := mod.Memory().WriteUint32Le(file+ptrSize, c.getFile(f)); !ok {
|
||||
panic(rangeErr)
|
||||
}
|
||||
id = len(c.files)
|
||||
c.files = append(c.files, f)
|
||||
found:
|
||||
|
||||
if ok := mod.Memory().WriteUint32Le(file+ptrSize, uint32(id)); !ok {
|
||||
if pOutFlags == 0 {
|
||||
return _OK
|
||||
}
|
||||
if ok := mod.Memory().WriteUint32Le(pOutFlags, flags); !ok {
|
||||
panic(rangeErr)
|
||||
}
|
||||
return _OK
|
||||
|
||||
Reference in New Issue
Block a user