Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
6b10c5cd
Commit
6b10c5cd
authored
7 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
implemented create file
parent
4ad1503b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
store/files.go
+31
-10
31 additions, 10 deletions
store/files.go
store/groups.go
+9
-5
9 additions, 5 deletions
store/groups.go
store/store_test.go
+27
-1
27 additions, 1 deletion
store/store_test.go
store/types.go
+2
-2
2 additions, 2 deletions
store/types.go
with
69 additions
and
18 deletions
store/files.go
+
31
−
10
View file @
6b10c5cd
...
...
@@ -26,6 +26,7 @@ package store
import
(
"encoding/json"
"errors"
"github.com/coreos/bbolt"
)
...
...
@@ -36,9 +37,17 @@ func getFilesBucket(tx *bolt.Tx, group string) (files *bolt.Bucket, err error) {
return
}
if
gb
==
nil
{
return
nil
,
nil
if
!
tx
.
Writable
()
{
return
// for read-only transactions this function might return nil for files
}
if
gb
,
err
=
createGroup
(
tx
,
group
);
err
!=
nil
{
return
}
}
files
=
gb
.
Bucket
([]
byte
(
filesBn
))
if
files
==
nil
{
err
=
errors
.
New
(
"invalid store: files bucket of group '"
+
group
+
"' not found"
)
}
return
}
...
...
@@ -51,12 +60,13 @@ func (st *Store) ListFiles(group string) (files Files, err error) {
if
fb
==
nil
{
return
nil
}
files
=
make
(
Files
)
err
=
fb
.
ForEach
(
func
(
k
,
v
[]
byte
)
error
{
var
file
File
if
err
:=
json
.
Unmarshal
(
v
,
file
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
v
,
&
file
);
err
!=
nil
{
return
err
}
files
=
append
(
files
,
file
)
files
[
string
(
k
)]
=
file
return
nil
})
return
err
...
...
@@ -64,19 +74,30 @@ func (st *Store) ListFiles(group string) (files Files, err error) {
return
}
func
(
st
*
Store
)
CreateFile
(
group
,
id
string
,
file
*
File
)
error
{
// TODO: implement this
return
ErrNotImplented
func
(
st
*
Store
)
CreateFile
(
group
string
,
file
File
)
(
id
string
,
err
error
)
{
err
=
st
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
fb
,
err
:=
getFilesBucket
(
tx
,
group
)
if
err
!=
nil
{
return
err
}
id
=
"1124235"
// TODO: create id using bolt sequences
v
,
err
:=
json
.
Marshal
(
file
)
if
err
!=
nil
{
return
err
}
return
fb
.
Put
([]
byte
(
id
),
v
)
})
return
}
func
(
st
*
Store
)
GetFile
(
group
,
id
string
)
(
*
File
,
error
)
{
func
(
st
*
Store
)
GetFile
(
group
,
id
string
)
(
File
,
error
)
{
// TODO: implement this
return
n
il
,
ErrNotImplented
return
F
il
e
{}
,
ErrNotImplented
}
func
(
st
*
Store
)
UpdateFile
(
group
,
id
string
,
new
File
)
(
*
File
,
error
)
{
func
(
st
*
Store
)
UpdateFile
(
group
,
id
string
,
new
File
)
(
File
,
error
)
{
// TODO: implement this
return
n
il
,
ErrNotImplented
return
F
il
e
{}
,
ErrNotImplented
}
func
(
st
*
Store
)
DeleteFile
(
group
,
id
string
)
error
{
...
...
This diff is collapsed.
Click to expand it.
store/groups.go
+
9
−
5
View file @
6b10c5cd
...
...
@@ -61,13 +61,17 @@ func newGroup(groups *bolt.Bucket, name string) (group *bolt.Bucket, err error)
return
}
func
createGroup
(
tx
*
bolt
.
Tx
,
name
string
)
(
*
bolt
.
Bucket
,
error
)
{
groups
,
err
:=
getGroupsBucket
(
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
newGroup
(
groups
,
name
)
}
func
(
st
*
Store
)
createGroup
(
name
string
)
(
err
error
)
{
err
=
st
.
db
.
Update
(
func
(
tx
*
bolt
.
Tx
)
error
{
gb
,
err
:=
getGroupsBucket
(
tx
)
if
err
!=
nil
{
return
err
}
_
,
err
=
newGroup
(
gb
,
name
)
_
,
err
:=
createGroup
(
tx
,
name
)
return
err
})
return
...
...
This diff is collapsed.
Click to expand it.
store/store_test.go
+
27
−
1
View file @
6b10c5cd
...
...
@@ -216,7 +216,7 @@ func TestGroups(t *testing.T) {
// Files
//
func
TestFiles
(
t
*
testing
.
T
)
{
func
TestFiles
ListAndCreate
(
t
*
testing
.
T
)
{
os
.
Remove
(
testDBPath
)
store
,
err
:=
NewStore
(
&
Config
{
testBasePath
})
if
err
!=
nil
{
...
...
@@ -238,4 +238,30 @@ func TestFiles(t *testing.T) {
if
len
(
files
)
!=
0
{
t
.
Fatalf
(
"listing files of not existing group should return and empty list but ListFiles returned: %q"
,
files
)
}
_
,
err
=
store
.
CreateFile
(
publicGroupBn
,
File
{})
if
err
!=
nil
{
t
.
Fatalf
(
"creating file in public group failed: %v"
,
err
)
}
files
,
err
=
store
.
ListFiles
(
publicGroupBn
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
files
)
!=
1
{
t
.
Fatalf
(
"ListFiles should return a single file but returned: %v"
,
files
)
}
_
,
err
=
store
.
CreateFile
(
testGroup1
,
File
{})
if
err
!=
nil
{
t
.
Fatalf
(
"creating file in not existing group shouldn't throw an error but CreateFile returned: %v"
,
err
)
}
groups
,
err
:=
store
.
ListGroups
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
!
stringInSlice
(
groups
,
testGroup1
)
{
t
.
Fatalf
(
"creating file in not existing group '%s' should create that group but ListGroups returned : %q"
,
testGroup1
,
groups
)
}
}
This diff is collapsed.
Click to expand it.
store/types.go
+
2
−
2
View file @
6b10c5cd
...
...
@@ -89,7 +89,7 @@ type File struct {
Dirty
bool
`json:"d"`
}
type
Files
[
]
File
type
Files
map
[
string
]
File
// stored in filesBn
type
Playlist
struct
{
...
...
@@ -98,4 +98,4 @@ type Playlist struct {
// TODO: playlist storage layout
}
type
Playlists
[
]
Playlist
type
Playlists
map
[
string
]
Playlist
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment