Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
e452f946
Commit
e452f946
authored
Sep 02, 2022
by
ZheNing Hu
Committed by
Han-Wen Nienhuys
Apr 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs: handle directories in zipfs example
Add a test. Change-Id: I8620e59ce2fc7b19f595c5670839735243fcd1bf
parent
17756c7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
fs/zip_test.go
fs/zip_test.go
+23
-2
fs/zipfs_example_test.go
fs/zipfs_example_test.go
+5
-0
No files found.
fs/zip_test.go
View file @
e452f946
...
@@ -9,8 +9,11 @@ import (
...
@@ -9,8 +9,11 @@ import (
"bytes"
"bytes"
"context"
"context"
"io/ioutil"
"io/ioutil"
"os"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"sort"
"strings"
"syscall"
"syscall"
"testing"
"testing"
...
@@ -19,6 +22,7 @@ import (
...
@@ -19,6 +22,7 @@ import (
var
testData
=
map
[
string
]
string
{
var
testData
=
map
[
string
]
string
{
"file.txt"
:
"content"
,
"file.txt"
:
"content"
,
"dir/"
:
""
,
"dir/subfile1"
:
"content2"
,
"dir/subfile1"
:
"content2"
,
"dir/subdir/subfile"
:
"content3"
,
"dir/subdir/subfile"
:
"content3"
,
}
}
...
@@ -27,9 +31,17 @@ func createZip(data map[string]string) []byte {
...
@@ -27,9 +31,17 @@ func createZip(data map[string]string) []byte {
buf
:=
&
bytes
.
Buffer
{}
buf
:=
&
bytes
.
Buffer
{}
zw
:=
zip
.
NewWriter
(
buf
)
zw
:=
zip
.
NewWriter
(
buf
)
for
k
,
v
:=
range
data
{
var
keys
[]
string
for
k
:=
range
data
{
keys
=
append
(
keys
,
k
)
}
sort
.
Strings
(
keys
)
for
_
,
k
:=
range
keys
{
fw
,
_
:=
zw
.
Create
(
k
)
fw
,
_
:=
zw
.
Create
(
k
)
fw
.
Write
([]
byte
(
v
))
d
:=
[]
byte
(
testData
[
k
])
if
len
(
d
)
>
0
{
fw
.
Write
(
d
)
}
}
}
zw
.
Close
()
zw
.
Close
()
...
@@ -67,6 +79,15 @@ func TestZipFS(t *testing.T) {
...
@@ -67,6 +79,15 @@ func TestZipFS(t *testing.T) {
defer
server
.
Unmount
()
defer
server
.
Unmount
()
for
k
,
v
:=
range
testData
{
for
k
,
v
:=
range
testData
{
if
strings
.
HasSuffix
(
k
,
"/"
)
{
fi
,
err
:=
os
.
Stat
(
filepath
.
Join
(
mntDir
,
k
))
if
err
!=
nil
{
t
.
Errorf
(
"stat %s: %v"
,
k
,
err
)
}
else
if
!
fi
.
IsDir
()
{
t
.
Errorf
(
"want isdir, got %v"
,
fi
)
}
continue
}
c
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
mntDir
,
k
))
c
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
mntDir
,
k
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
...
fs/zipfs_example_test.go
View file @
e452f946
...
@@ -107,6 +107,11 @@ func (zr *zipRoot) OnAdd(ctx context.Context) {
...
@@ -107,6 +107,11 @@ func (zr *zipRoot) OnAdd(ctx context.Context) {
p
=
ch
p
=
ch
}
}
if
f
.
FileInfo
()
.
IsDir
()
{
continue
}
ch
:=
p
.
NewPersistentInode
(
ctx
,
&
zipFile
{
file
:
f
},
fs
.
StableAttr
{})
ch
:=
p
.
NewPersistentInode
(
ctx
,
&
zipFile
{
file
:
f
},
fs
.
StableAttr
{})
p
.
AddChild
(
base
,
ch
,
true
)
p
.
AddChild
(
base
,
ch
,
true
)
}
}
...
...
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