mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Filenames.
This commit is contained in:
2
conn.go
2
conn.go
@@ -228,7 +228,7 @@ func (c *Conn) Filename(schema string) *vfs.Filename {
|
||||
ptr = c.arena.string(schema)
|
||||
}
|
||||
r := c.call("sqlite3_db_filename", uint64(c.handle), uint64(ptr))
|
||||
return vfs.OpenFilename(c.ctx, c.mod, uint32(r), vfs.OPEN_MAIN_DB)
|
||||
return vfs.GetFilename(c.ctx, c.mod, uint32(r), vfs.OPEN_MAIN_DB)
|
||||
}
|
||||
|
||||
// ReadOnly determines if a database is read-only.
|
||||
|
||||
@@ -17,6 +17,7 @@ type hbshVFS struct {
|
||||
}
|
||||
|
||||
func (h *hbshVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
|
||||
// notest // OpenFilename is called instead
|
||||
return nil, 0, sqlite3.CANTOPEN
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ func (vfsOS) Access(name string, flags AccessFlag) (bool, error) {
|
||||
}
|
||||
|
||||
func (vfsOS) Open(name string, flags OpenFlag) (File, OpenFlag, error) {
|
||||
// notest // OpenFilename is called instead
|
||||
return nil, 0, _CANTOPEN
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ type Filename struct {
|
||||
stack [2]uint64
|
||||
}
|
||||
|
||||
// OpenFilename is an internal API users should not call directly.
|
||||
func OpenFilename(ctx context.Context, mod api.Module, id uint32, flags OpenFlag) *Filename {
|
||||
// GetFilename is an internal API users should not call directly.
|
||||
func GetFilename(ctx context.Context, mod api.Module, id uint32, flags OpenFlag) *Filename {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -66,6 +66,10 @@ func (n *Filename) path(method string) string {
|
||||
if n == nil || n.zPath == 0 {
|
||||
return ""
|
||||
}
|
||||
if n.flags&(OPEN_MAIN_DB|OPEN_MAIN_JOURNAL|OPEN_WAL) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
n.stack[0] = uint64(n.zPath)
|
||||
fn := n.mod.ExportedFunction(method)
|
||||
if err := fn.CallWithStack(n.ctx, n.stack[:]); err != nil {
|
||||
|
||||
10
vfs/vfs.go
10
vfs/vfs.go
@@ -132,26 +132,20 @@ func vfsAccess(ctx context.Context, mod api.Module, pVfs, zPath uint32, flags Ac
|
||||
|
||||
func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, flags OpenFlag, pOutFlags, pOutVFS uint32) _ErrorCode {
|
||||
vfs := vfsGet(mod, pVfs)
|
||||
|
||||
var path string
|
||||
if zPath != 0 {
|
||||
path = util.ReadString(mod, zPath, _MAX_PATHNAME)
|
||||
}
|
||||
name := GetFilename(ctx, mod, zPath, flags)
|
||||
|
||||
var file File
|
||||
var err error
|
||||
if ffs, ok := vfs.(VFSFilename); ok {
|
||||
name := OpenFilename(ctx, mod, zPath, flags)
|
||||
file, flags, err = ffs.OpenFilename(name, flags)
|
||||
} else {
|
||||
file, flags, err = vfs.Open(path, flags)
|
||||
file, flags, err = vfs.Open(name.String(), flags)
|
||||
}
|
||||
if err != nil {
|
||||
return vfsErrorCode(err, _CANTOPEN)
|
||||
}
|
||||
|
||||
if file, ok := file.(FilePowersafeOverwrite); ok {
|
||||
name := OpenFilename(ctx, mod, zPath, flags)
|
||||
if b, ok := util.ParseBool(name.URIParameter("psow")); ok {
|
||||
file.SetPowersafeOverwrite(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user