Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
rednerd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
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
orus-io
rednerd
Commits
edc968552f0a
Commit
edc968552f0a
authored
6 days ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
Add a layered FS type that will be passed down to engines
parent
46de2830176a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/fs.go
+108
-0
108 additions, 0 deletions
lib/fs.go
models/fs.go
+40
-0
40 additions, 0 deletions
models/fs.go
with
148 additions
and
0 deletions
lib/fs.go
0 → 100644
+
108
−
0
View file @
edc96855
package
redner
import
(
"encoding/hex"
"io"
"os"
"slices"
"strings"
"orus.io/orus-io/go-orusapi/database"
"orus.io/orus-io/rednerd/models"
)
func
ancestors
(
path
string
)
[]
string
{
segments
:=
slices
.
Insert
(
strings
.
Split
(
strings
.
Trim
(
path
,
"/"
),
"/"
),
0
,
""
)
for
i
:=
range
segments
[
1
:
]
{
segments
[
i
+
1
]
=
segments
[
i
]
+
"/"
+
segments
[
i
+
1
]
}
segments
[
0
]
=
"/"
return
segments
}
type
fsLayer
struct
{
root
string
files
[]
*
models
.
File
}
type
FS
struct
{
db
*
database
.
SQLHelper
layers
[]
fsLayer
masked
[]
string
fileIndex
map
[
string
]
*
models
.
File
fileList
[]
*
models
.
File
fileRoot
map
[
string
]
string
}
func
NewFS
(
db
*
database
.
SQLHelper
)
*
FS
{
return
&
FS
{
db
:
db
}
}
func
(
fs
*
FS
)
AddRoot
(
root
string
)
error
{
nodes
,
err
:=
models
.
ListFiles
(
fs
.
db
,
root
,
"/"
)
if
err
!=
nil
{
return
err
}
files
:=
make
([]
*
models
.
File
,
len
(
nodes
))
for
i
,
node
:=
range
nodes
{
files
[
i
]
=
&
models
.
File
{
Path
:
node
.
Path
,
Type
:
node
.
Mimetype
,
Sha256
:
hex
.
EncodeToString
(
node
.
Sha256
),
Size
:
node
.
Size
,
}
}
fs
.
AddLayer
(
root
,
files
)
return
nil
}
func
(
fs
*
FS
)
AddLayer
(
root
string
,
files
[]
*
models
.
File
)
{
nextMasked
:=
slices
.
Clone
(
fs
.
masked
)
for
_
,
f
:=
range
files
{
if
slices
.
ContainsFunc
(
ancestors
(
f
.
Path
),
func
(
p
string
)
bool
{
return
slices
.
Contains
(
fs
.
masked
,
p
)
})
{
continue
}
if
f
.
Type
==
"redner/mask"
{
nextMasked
=
append
(
nextMasked
,
f
.
Path
)
}
else
if
_
,
exists
:=
fs
.
fileIndex
[
f
.
Path
];
!
exists
{
fs
.
fileRoot
[
f
.
Path
]
=
root
fs
.
fileIndex
[
f
.
Path
]
=
f
}
}
fs
.
masked
=
nextMasked
fs
.
layers
=
append
(
fs
.
layers
,
fsLayer
{
root
:
root
,
files
:
files
,
})
fs
.
fileList
=
make
([]
*
models
.
File
,
0
,
len
(
fs
.
fileIndex
))
for
_
,
v
:=
range
fs
.
fileIndex
{
fs
.
fileList
=
append
(
fs
.
fileList
,
v
)
}
}
func
(
fs
*
FS
)
List
()
[]
*
models
.
File
{
return
fs
.
fileList
}
func
(
fs
*
FS
)
Read
(
path
string
)
(
io
.
ReadCloser
,
error
)
{
f
,
ok
:=
fs
.
fileIndex
[
path
]
if
!
ok
{
return
nil
,
os
.
ErrNotExist
}
// root := fs.fileRoot[path]
return
models
.
GetFileBody
(
fs
.
db
,
f
.
Sha256
)
}
This diff is collapsed.
Click to expand it.
models/fs.go
+
40
−
0
View file @
edc96855
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
(
import
(
"bytes"
"bytes"
"crypto/sha256"
"crypto/sha256"
"encoding/hex"
"io"
"io"
"slices"
"slices"
"strings"
"strings"
...
@@ -39,6 +40,22 @@
...
@@ -39,6 +40,22 @@
return
io
.
NopCloser
(
bytes
.
NewReader
(
data
)),
nil
return
io
.
NopCloser
(
bytes
.
NewReader
(
data
)),
nil
}
}
func
GetFileBody
(
db
*
database
.
SQLHelper
,
sha256Hex
string
)
(
io
.
ReadCloser
,
error
)
{
sha
,
err
:=
hex
.
DecodeString
(
sha256Hex
)
if
err
!=
nil
{
return
nil
,
err
}
var
data
[]
byte
if
err
:=
db
.
Get
(
&
data
,
squirrel
.
Select
(
"body"
)
.
From
(
"fscontent"
)
.
Where
(
squirrel
.
Eq
{
"sha256"
:
sha
}),
);
err
!=
nil
{
return
nil
,
err
}
return
io
.
NopCloser
(
bytes
.
NewReader
(
data
)),
nil
}
func
InsertFile
(
db
*
database
.
SQLHelper
,
node
*
FSNode
,
body
[]
byte
)
error
{
func
InsertFile
(
db
*
database
.
SQLHelper
,
node
*
FSNode
,
body
[]
byte
)
error
{
node
.
Path
=
"/"
+
strings
.
Trim
(
node
.
Path
,
"/"
)
node
.
Path
=
"/"
+
strings
.
Trim
(
node
.
Path
,
"/"
)
...
@@ -115,3 +132,26 @@
...
@@ -115,3 +132,26 @@
return
nil
return
nil
}
}
func
ListFiles
(
db
*
database
.
SQLHelper
,
root
string
,
path
string
)
([]
FSNode
,
error
)
{
var
files
[]
FSNode
if
err
:=
db
.
Select
(
&
files
,
squirrel
.
Select
(
Schema
.
FSNode
.
FQColumns
(
true
)
...
,
)
.
From
(
Schema
.
FSNode
.
GetName
())
.
LeftJoin
(
"fsclosure ON fsclosure.root = fsnode.root AND fsclosure.child_path = fsnode.path"
,
)
.
Where
(
squirrel
.
Eq
{
"fsclosure.root"
:
root
,
"fsclosure.parent_path"
:
path
,
}),
);
err
!=
nil
{
return
nil
,
err
}
return
files
,
nil
}
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