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
6db29c0a
Commit
6db29c0a
authored
Jan 13, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use constants for SHARDING and _README file names.
parent
9d9fdda1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
flatfs.go
flatfs.go
+2
-2
flatfs_test.go
flatfs_test.go
+3
-3
shard.go
shard.go
+5
-3
No files found.
flatfs.go
View file @
6db29c0a
...
...
@@ -43,7 +43,7 @@ type ShardFunc func(string) string
var
(
ErrDatastoreExists
=
errors
.
New
(
"datastore already exist"
)
ErrDatastoreDoesNotExist
=
errors
.
New
(
"datastore directory does not exist"
)
ErrShardingFileMissing
=
errors
.
New
(
"SHARDING
file not found in datastore"
)
ErrShardingFileMissing
=
fmt
.
Errorf
(
"%s
file not found in datastore"
,
SHARDING_FN
)
)
const
IPFS_DEF_SHARD
=
"/repo/flatfs/shard/v1/next-to-last/2"
...
...
@@ -68,7 +68,7 @@ func Create(path string, funStr string) error {
return
err
}
if
!
isEmpty
{
return
fmt
.
Errorf
(
"directory missing
SHARDING
file: %s"
,
path
)
return
fmt
.
Errorf
(
"directory missing
%s
file: %s"
,
SHARDING_FN
,
path
)
}
err
=
WriteShardFunc
(
path
,
fun
)
...
...
flatfs_test.go
View file @
6db29c0a
...
...
@@ -183,9 +183,9 @@ func testStorage(p *params, t *testing.T) {
return
err
}
switch
path
{
case
"."
,
".."
,
"
SHARDING
"
:
case
"."
,
".."
,
flatfs
.
SHARDING
_FN
:
// ignore
case
"_
README
"
:
case
flatfs
.
README
_FN
:
_
,
err
:=
ioutil
.
ReadFile
(
absPath
)
if
err
!=
nil
{
t
.
Error
(
"could not read _README file"
)
...
...
@@ -487,7 +487,7 @@ func TestNoCluster(t *testing.T) {
tolerance
:=
math
.
Floor
(
idealFilesPerDir
*
0.20
)
count
:=
0
for
_
,
dir
:=
range
dirs
{
if
dir
.
Name
()
==
"
SHARDING
"
{
if
dir
.
Name
()
==
flatfs
.
SHARDING
_FN
||
dir
.
Name
()
==
flatfs
.
README_FN
{
continue
}
count
+=
1
...
...
shard.go
View file @
6db29c0a
...
...
@@ -16,6 +16,8 @@ type ShardIdV1 struct {
}
const
PREFIX
=
"/repo/flatfs/shard/"
const
SHARDING_FN
=
"SHARDING"
const
README_FN
=
"README"
func
(
f
*
ShardIdV1
)
String
()
string
{
return
fmt
.
Sprintf
(
"%sv1/%s/%d"
,
PREFIX
,
f
.
funName
,
f
.
param
)
...
...
@@ -72,7 +74,7 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
}
func
ReadShardFunc
(
dir
string
)
(
*
ShardIdV1
,
error
)
{
buf
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
dir
,
"
SHARDING
"
))
buf
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
dir
,
SHARDING
_FN
))
if
os
.
IsNotExist
(
err
)
{
return
nil
,
ErrShardingFileMissing
}
else
if
err
!=
nil
{
...
...
@@ -82,7 +84,7 @@ func ReadShardFunc(dir string) (*ShardIdV1, error) {
}
func
WriteShardFunc
(
dir
string
,
id
*
ShardIdV1
)
error
{
file
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"
SHARDING
"
))
file
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
SHARDING
_FN
))
if
err
!=
nil
{
return
err
}
...
...
@@ -97,7 +99,7 @@ func WriteShardFunc(dir string, id *ShardIdV1) error {
func
WriteReadme
(
dir
string
,
id
*
ShardIdV1
)
error
{
if
id
.
String
()
==
IPFS_DEF_SHARD
{
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"_
README
"
),
[]
byte
(
README_IPFS_DEF_SHARD
),
0444
)
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
README
_FN
),
[]
byte
(
README_IPFS_DEF_SHARD
),
0444
)
if
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