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-ds-flatfs
Commits
a156e6fa
Commit
a156e6fa
authored
Jan 16, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup: Move things around so they are in more logical locations.
parent
ceebea7e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
46 deletions
+47
-46
flatfs.go
flatfs.go
+2
-5
shard.go
shard.go
+45
-41
No files found.
flatfs.go
View file @
a156e6fa
...
@@ -36,19 +36,16 @@ type Datastore struct {
...
@@ -36,19 +36,16 @@ type Datastore struct {
sync
bool
sync
bool
}
}
var
_
datastore
.
Datastore
=
(
*
Datastore
)(
nil
)
type
ShardFunc
func
(
string
)
string
type
ShardFunc
func
(
string
)
string
var
_
datastore
.
Datastore
=
(
*
Datastore
)(
nil
)
var
(
var
(
ErrDatastoreExists
=
errors
.
New
(
"datastore already exist"
)
ErrDatastoreExists
=
errors
.
New
(
"datastore already exist"
)
ErrDatastoreDoesNotExist
=
errors
.
New
(
"datastore directory does not exist"
)
ErrDatastoreDoesNotExist
=
errors
.
New
(
"datastore directory does not exist"
)
ErrShardingFileMissing
=
fmt
.
Errorf
(
"%s file not found in datastore"
,
SHARDING_FN
)
ErrShardingFileMissing
=
fmt
.
Errorf
(
"%s file not found in datastore"
,
SHARDING_FN
)
)
)
var
IPFS_DEF_SHARD
=
NextToLast
(
2
)
var
IPFS_DEF_SHARD_STR
=
IPFS_DEF_SHARD
.
String
()
func
Create
(
path
string
,
fun
*
ShardIdV1
)
error
{
func
Create
(
path
string
,
fun
*
ShardIdV1
)
error
{
err
:=
os
.
Mkdir
(
path
,
0777
)
err
:=
os
.
Mkdir
(
path
,
0777
)
...
...
shard.go
View file @
a156e6fa
...
@@ -9,16 +9,20 @@ import (
...
@@ -9,16 +9,20 @@ import (
"strings"
"strings"
)
)
var
IPFS_DEF_SHARD
=
NextToLast
(
2
)
var
IPFS_DEF_SHARD_STR
=
IPFS_DEF_SHARD
.
String
()
const
PREFIX
=
"/repo/flatfs/shard/"
const
SHARDING_FN
=
"SHARDING"
const
README_FN
=
"README"
type
ShardIdV1
struct
{
type
ShardIdV1
struct
{
funName
string
funName
string
param
int
param
int
fun
ShardFunc
fun
ShardFunc
}
}
const
PREFIX
=
"/repo/flatfs/shard/"
const
SHARDING_FN
=
"SHARDING"
const
README_FN
=
"README"
func
(
f
*
ShardIdV1
)
String
()
string
{
func
(
f
*
ShardIdV1
)
String
()
string
{
return
fmt
.
Sprintf
(
"%sv1/%s/%d"
,
PREFIX
,
f
.
funName
,
f
.
param
)
return
fmt
.
Sprintf
(
"%sv1/%s/%d"
,
PREFIX
,
f
.
funName
,
f
.
param
)
}
}
...
@@ -27,9 +31,45 @@ func (f *ShardIdV1) Func() ShardFunc {
...
@@ -27,9 +31,45 @@ func (f *ShardIdV1) Func() ShardFunc {
return
f
.
fun
return
f
.
fun
}
}
func
Prefix
(
prefixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
prefixLen
)
return
&
ShardIdV1
{
funName
:
"prefix"
,
param
:
prefixLen
,
fun
:
func
(
noslash
string
)
string
{
return
(
noslash
+
padding
)[
:
prefixLen
]
},
}
}
func
Suffix
(
suffixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
suffixLen
)
return
&
ShardIdV1
{
funName
:
"suffix"
,
param
:
suffixLen
,
fun
:
func
(
noslash
string
)
string
{
str
:=
padding
+
noslash
return
str
[
len
(
str
)
-
suffixLen
:
]
},
}
}
func
NextToLast
(
suffixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
suffixLen
+
1
)
return
&
ShardIdV1
{
funName
:
"next-to-last"
,
param
:
suffixLen
,
fun
:
func
(
noslash
string
)
string
{
str
:=
padding
+
noslash
offset
:=
len
(
str
)
-
suffixLen
-
1
return
str
[
offset
:
offset
+
suffixLen
]
},
}
}
func
ParseShardFunc
(
str
string
)
(
*
ShardIdV1
,
error
)
{
func
ParseShardFunc
(
str
string
)
(
*
ShardIdV1
,
error
)
{
str
=
strings
.
TrimSpace
(
str
)
str
=
strings
.
TrimSpace
(
str
)
// ignore prefix for now
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"empty shard identifier"
)
return
nil
,
fmt
.
Errorf
(
"empty shard identifier"
)
}
}
...
@@ -104,39 +144,3 @@ func WriteReadme(dir string, id *ShardIdV1) error {
...
@@ -104,39 +144,3 @@ func WriteReadme(dir string, id *ShardIdV1) error {
}
}
return
nil
return
nil
}
}
func
Prefix
(
prefixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
prefixLen
)
return
&
ShardIdV1
{
funName
:
"prefix"
,
param
:
prefixLen
,
fun
:
func
(
noslash
string
)
string
{
return
(
noslash
+
padding
)[
:
prefixLen
]
},
}
}
func
Suffix
(
suffixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
suffixLen
)
return
&
ShardIdV1
{
funName
:
"suffix"
,
param
:
suffixLen
,
fun
:
func
(
noslash
string
)
string
{
str
:=
padding
+
noslash
return
str
[
len
(
str
)
-
suffixLen
:
]
},
}
}
func
NextToLast
(
suffixLen
int
)
*
ShardIdV1
{
padding
:=
strings
.
Repeat
(
"_"
,
suffixLen
+
1
)
return
&
ShardIdV1
{
funName
:
"next-to-last"
,
param
:
suffixLen
,
fun
:
func
(
noslash
string
)
string
{
str
:=
padding
+
noslash
offset
:=
len
(
str
)
-
suffixLen
-
1
return
str
[
offset
:
offset
+
suffixLen
]
},
}
}
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