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-datastore
Commits
024754e6
Commit
024754e6
authored
Dec 13, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use filepath walk for flatfs query
parent
bec407bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
43 deletions
+25
-43
flatfs/flatfs.go
flatfs/flatfs.go
+25
-43
No files found.
flatfs/flatfs.go
View file @
024754e6
...
...
@@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"time"
...
...
@@ -314,52 +315,33 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
return
nil
,
errors
.
New
(
"flatfs only supports listing all keys in random order"
)
}
// TODO this dumb implementation gathers all keys into a single slice.
root
,
err
:=
os
.
Open
(
fs
.
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
root
.
Close
()
reschan
:=
make
(
chan
query
.
Result
)
go
func
()
{
defer
close
(
reschan
)
err
:=
filepath
.
Walk
(
fs
.
path
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
var
res
[]
query
.
Entry
prefixes
,
err
:=
root
.
Readdir
(
0
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
fi
:=
range
prefixes
{
var
err
error
res
,
err
=
fs
.
enumerateKeys
(
fi
,
res
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
query
.
ResultsWithEntries
(
q
,
res
),
nil
}
if
!
info
.
Mode
()
.
IsRegular
()
||
info
.
Name
()[
0
]
==
'.'
{
return
nil
}
func
(
fs
*
Datastore
)
enumerateKeys
(
fi
os
.
FileInfo
,
res
[]
query
.
Entry
)
([]
query
.
Entry
,
error
)
{
if
!
fi
.
IsDir
()
||
fi
.
Name
()[
0
]
==
'.'
{
return
res
,
nil
}
child
,
err
:=
os
.
Open
(
path
.
Join
(
fs
.
path
,
fi
.
Name
()))
if
err
!=
nil
{
return
nil
,
err
}
defer
child
.
Close
()
objs
,
err
:=
child
.
Readdir
(
0
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
fi
:=
range
objs
{
if
!
fi
.
Mode
()
.
IsRegular
()
||
fi
.
Name
()[
0
]
==
'.'
{
return
res
,
nil
}
key
,
ok
:=
fs
.
decode
(
fi
.
Name
())
if
!
ok
{
return
res
,
nil
key
,
ok
:=
fs
.
decode
(
info
.
Name
())
if
!
ok
{
log
.
Warning
(
"failed to decode entry in flatfs"
)
return
nil
}
reschan
<-
query
.
Result
{
Entry
:
query
.
Entry
{
Key
:
key
.
String
(),
},
}
return
nil
})
if
err
!=
nil
{
log
.
Warning
(
"walk failed: "
,
err
)
}
res
=
append
(
res
,
query
.
Entry
{
Key
:
key
.
String
()})
}
return
res
,
nil
}()
return
query
.
ResultsWithChan
(
q
,
reschan
),
nil
}
func
(
fs
*
Datastore
)
Close
()
error
{
...
...
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