Commit 9f0738e5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0e825b2f
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package fs1
// URL support
import (
"net/url"
"../../zodb"
)
// TODO read-only support
func openByURL(u *url.URL) (zodb.IStorage, error) {
// TODO handle query
// XXX u.Path is not always raw path - recheck and fix
return Open(u.Path)
}
func init() {
zodb.RegisterStorage("file://", openByURL)
}
...@@ -24,8 +24,9 @@ import ( ...@@ -24,8 +24,9 @@ import (
"os" "os"
"../../zodbtools" "../../zodbtools"
)
_ "../../../zodb/wks"
)
func usage() { func usage() {
w := os.Stderr w := os.Stderr
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package zodb
// logic to open storages by URL
import (
"net/url"
"strings"
)
// OpenStorage opens ZODB storage by URL
// Only URL schemes registered to zodb package are handled.
// Users should user import in storage packages they use or zodb/wks package to
// get support work well-known storages.
// Storage authors should register their storages with RegisterStorage
//
// TODO readonly
func OpenStorageURL(storageURL string) (IStorage, error) {
// no scheme -> file://
if !strings.Contains(storageURL, "://") {
storageURL = "file://" + storageURL
}
return nil, nil
}
// StorageOpener is a function to open a storage
type StorageOpener func (u *url.URL) (IStorage, error)
// RegisterStorage registers handler to be used for URLs with scheme
func RegisterStorage(scheme string, handler StorageOpener) {
// TODO
}
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// Package wks links-in well-known ZODB storages
// The only purpose of this package is so that users import it
//
// import _ ".../zodb/wks" XXX fixme import path
//
// and this way automatically link in support for file:// neo:// ... storages.
package wks
import (
_ "../../storage/fs1"
)
...@@ -158,11 +158,3 @@ type IStorageRecordIterator interface { // XXX naming -> IRecordIterator ...@@ -158,11 +158,3 @@ type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
// end of iteration is indicated with io.EOF // end of iteration is indicated with io.EOF
NextData() (*StorageRecordInformation, error) NextData() (*StorageRecordInformation, error)
} }
// TODO readonly
func Open(storageURL string) (IStorage, error) {
// TODO
return nil, nil
}
...@@ -18,9 +18,7 @@ ...@@ -18,9 +18,7 @@
package zodbtools package zodbtools
// registry for all commands // registry for all commands
import ( import "io"
"io"
)
// Command describes one zodb subcommand // Command describes one zodb subcommand
type Command struct { type Command struct {
......
...@@ -47,7 +47,6 @@ import ( ...@@ -47,7 +47,6 @@ import (
"lab.nexedi.com/kirr/go123/xfmt" "lab.nexedi.com/kirr/go123/xfmt"
"../../zodb" "../../zodb"
// "../../storage/fs1"
) )
...@@ -246,7 +245,7 @@ func dumpMain(argv []string) { ...@@ -246,7 +245,7 @@ func dumpMain(argv []string) {
log.Fatal(err) // XXX recheck log.Fatal(err) // XXX recheck
} }
stor, err := zodb.Open(storUrl) // TODO read-only stor, err := zodb.OpenStorageURL(storUrl) // TODO read-only
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -86,7 +86,7 @@ func TestZodbDump(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestZodbDump(t *testing.T) {
withTestdata1Fs(t, func(fs *fs1.FileStorage) { withTestdata1Fs(t, func(fs *fs1.FileStorage) {
buf := bytes.Buffer{} buf := bytes.Buffer{}
err := zodbDump(&buf, fs, 0, zodb.TidMax, false) err := Dump(&buf, fs, 0, zodb.TidMax, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -106,7 +106,7 @@ func BenchmarkZodbDump(b *testing.B) { ...@@ -106,7 +106,7 @@ func BenchmarkZodbDump(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
err := zodbDump(ioutil.Discard, fs, 0, zodb.TidMax, false) err := Dump(ioutil.Discard, fs, 0, zodb.TidMax, false)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
......
...@@ -35,6 +35,7 @@ type paramFunc func(stor zodb.IStorage) (string, error) ...@@ -35,6 +35,7 @@ type paramFunc func(stor zodb.IStorage) (string, error)
var infov = []struct {name string; getParam paramFunc} { var infov = []struct {name string; getParam paramFunc} {
// XXX e.g. stor.LastTid() should return err itself // XXX e.g. stor.LastTid() should return err itself
{"name", func(stor zodb.IStorage) (string, error) { return stor.StorageName(), nil }}, {"name", func(stor zodb.IStorage) (string, error) { return stor.StorageName(), nil }},
// TODO reenable size
// {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }}, // {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }},
{"last_tid", func(stor zodb.IStorage) (string, error) {return stor.LastTid().String(), nil }}, {"last_tid", func(stor zodb.IStorage) (string, error) {return stor.LastTid().String(), nil }},
} }
...@@ -112,7 +113,7 @@ func infoMain(argv []string) { ...@@ -112,7 +113,7 @@ func infoMain(argv []string) {
} }
storUrl := argv[0] storUrl := argv[0]
stor, err := zodb.Open(storUrl) // TODO read-only stor, err := zodb.OpenStorageURL(storUrl) // TODO read-only
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment