Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
4ba4ee3a
Commit
4ba4ee3a
authored
Jan 14, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(fsrepo/component.datastore) basic shell
parent
7ad559b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
repo/fsrepo/component/datastore.go
repo/fsrepo/component/datastore.go
+64
-0
No files found.
repo/fsrepo/component/datastore.go
0 → 100644
View file @
4ba4ee3a
package
component
import
(
datastore
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
levelds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/leveldb"
ldbopts
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
config
"github.com/jbenet/go-ipfs/repo/config"
dir
"github.com/jbenet/go-ipfs/repo/fsrepo/dir"
util
"github.com/jbenet/go-ipfs/util"
ds2
"github.com/jbenet/go-ipfs/util/datastore2"
debugerror
"github.com/jbenet/go-ipfs/util/debugerror"
)
var
_
Component
=
&
DatastoreComponent
{}
var
_
Initializer
=
InitDatastoreComponent
var
_
InitializationChecker
=
DatastoreComponentIsInitialized
func
InitDatastoreComponent
(
path
string
,
conf
*
config
.
Config
)
error
{
// The actual datastore contents are initialized lazily when Opened.
// During Init, we merely check that the directory is writeable.
dspath
,
err
:=
config
.
DataStorePath
(
path
)
if
err
!=
nil
{
return
err
}
if
err
:=
dir
.
Writable
(
dspath
);
err
!=
nil
{
return
debugerror
.
Errorf
(
"datastore: %s"
,
err
)
}
return
nil
}
// DatastoreComponentIsInitialized returns true if the datastore dir exists.
func
DatastoreComponentIsInitialized
(
path
string
)
bool
{
dspath
,
err
:=
config
.
DataStorePath
(
path
)
if
err
!=
nil
{
return
false
}
if
!
util
.
FileExists
(
dspath
)
{
return
false
}
return
true
}
// DatastoreComponent abstracts the datastore component of the FSRepo.
// NB: create with makeDatastoreComponent function.
type
DatastoreComponent
struct
{
path
string
ds
ds2
.
ThreadSafeDatastoreCloser
}
// Open returns an error if the config file is not present.
func
(
dsc
*
DatastoreComponent
)
Open
()
error
{
ds
,
err
:=
levelds
.
NewDatastore
(
dsc
.
path
,
&
levelds
.
Options
{
Compression
:
ldbopts
.
NoCompression
,
})
if
err
!=
nil
{
return
err
}
dsc
.
ds
=
ds
return
nil
}
func
(
dsc
*
DatastoreComponent
)
Close
()
error
{
return
dsc
.
ds
.
Close
()
}
func
(
dsc
*
DatastoreComponent
)
SetPath
(
p
string
)
{
dsc
.
path
=
p
}
func
(
dsc
*
DatastoreComponent
)
Datastore
()
datastore
.
ThreadSafeDatastore
{
return
dsc
.
ds
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment