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
7ad559b8
Commit
7ad559b8
authored
Jan 14, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(fsrepo, component): expose SetPath to ensure that components handle paths
parent
b6603051
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
6 deletions
+12
-6
repo/fsrepo/component/component.go
repo/fsrepo/component/component.go
+1
-0
repo/fsrepo/component/config.go
repo/fsrepo/component/config.go
+9
-5
repo/fsrepo/fsrepo.go
repo/fsrepo/fsrepo.go
+2
-1
No files found.
repo/fsrepo/component/component.go
View file @
7ad559b8
...
...
@@ -9,6 +9,7 @@ import (
type
Component
interface
{
Open
()
error
io
.
Closer
SetPath
(
string
)
}
type
Initializer
func
(
path
string
,
conf
*
config
.
Config
)
error
type
InitializationChecker
func
(
path
string
)
bool
repo/fsrepo/component/config.go
View file @
7ad559b8
...
...
@@ -15,7 +15,7 @@ var _ InitializationChecker = ConfigComponentIsInitialized
// NB: create with makeConfigComponent function.
// NOT THREAD-SAFE
type
ConfigComponent
struct
{
P
ath
string
// required at instantiation
p
ath
string
// required at instantiation
config
*
config
.
Config
// assigned on Open()
}
...
...
@@ -39,7 +39,7 @@ func InitConfigComponent(path string, conf *config.Config) error {
// Open returns an error if the config file is not present.
func
(
c
*
ConfigComponent
)
Open
()
error
{
configFilename
,
err
:=
config
.
Filename
(
c
.
P
ath
)
configFilename
,
err
:=
config
.
Filename
(
c
.
p
ath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -67,7 +67,7 @@ func (c *ConfigComponent) SetConfig(updated *config.Config) error {
// GetConfigKey retrieves only the value of a particular key.
func
(
c
*
ConfigComponent
)
GetConfigKey
(
key
string
)
(
interface
{},
error
)
{
filename
,
err
:=
config
.
Filename
(
c
.
P
ath
)
filename
,
err
:=
config
.
Filename
(
c
.
p
ath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -80,7 +80,7 @@ func (c *ConfigComponent) GetConfigKey(key string) (interface{}, error) {
// SetConfigKey writes the value of a particular key.
func
(
c
*
ConfigComponent
)
SetConfigKey
(
key
string
,
value
interface
{})
error
{
filename
,
err
:=
config
.
Filename
(
c
.
P
ath
)
filename
,
err
:=
config
.
Filename
(
c
.
p
ath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -103,6 +103,10 @@ func (c *ConfigComponent) SetConfigKey(key string, value interface{}) error {
return
c
.
setConfigUnsynced
(
conf
)
// TODO roll this into this method
}
func
(
c
*
ConfigComponent
)
SetPath
(
p
string
)
{
c
.
path
=
p
}
// ConfigComponentIsInitialized returns true if the repo is initialized at
// provided |path|.
func
ConfigComponentIsInitialized
(
path
string
)
bool
{
...
...
@@ -118,7 +122,7 @@ func ConfigComponentIsInitialized(path string) bool {
// setConfigUnsynced is for private use.
func
(
r
*
ConfigComponent
)
setConfigUnsynced
(
updated
*
config
.
Config
)
error
{
configFilename
,
err
:=
config
.
Filename
(
r
.
P
ath
)
configFilename
,
err
:=
config
.
Filename
(
r
.
p
ath
)
if
err
!=
nil
{
return
err
}
...
...
repo/fsrepo/fsrepo.go
View file @
7ad559b8
...
...
@@ -314,7 +314,8 @@ func componentBuilders() []componentBuilder {
Init
:
component
.
InitConfigComponent
,
IsInitialized
:
component
.
ConfigComponentIsInitialized
,
OpenHandler
:
func
(
r
*
FSRepo
)
error
{
cc
:=
component
.
ConfigComponent
{
Path
:
r
.
path
}
cc
:=
component
.
ConfigComponent
{}
cc
.
SetPath
(
r
.
path
)
if
err
:=
cc
.
Open
();
err
!=
nil
{
return
err
}
...
...
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