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
1abae81d
Commit
1abae81d
authored
Apr 08, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tarfs: handle empty directories, handle more file types
parent
0f68fcc4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
13 deletions
+45
-13
zipfs/tarfs.go
zipfs/tarfs.go
+32
-10
zipfs/tarfs_test.go
zipfs/tarfs_test.go
+13
-3
No files found.
zipfs/tarfs.go
View file @
1abae81d
...
...
@@ -52,7 +52,6 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
// XXX handle error
break
}
if
hdr
.
Typeflag
==
'L'
{
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
io
.
Copy
(
buf
,
tr
)
...
...
@@ -66,10 +65,6 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
longName
=
nil
}
if
strings
.
HasSuffix
(
hdr
.
Name
,
"/"
)
{
continue
}
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
io
.
Copy
(
buf
,
tr
)
dir
,
base
:=
filepath
.
Split
(
filepath
.
Clean
(
hdr
.
Name
))
...
...
@@ -89,16 +84,43 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
p
=
ch
}
if
hdr
.
Typeflag
==
tar
.
TypeSymlink
{
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
&
nodefs
.
MemSymlink
{
var
attr
fuse
.
Attr
HeaderToFileInfo
(
&
attr
,
hdr
)
switch
hdr
.
Typeflag
{
case
tar
.
TypeSymlink
:
l
:=
&
nodefs
.
MemSymlink
{
Data
:
[]
byte
(
hdr
.
Linkname
),
},
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFLNK
}),
false
)
}
else
{
}
l
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
l
,
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFLNK
}),
false
)
case
tar
.
TypeLink
:
log
.
Println
(
"don't know how to handle Typelink"
)
case
tar
.
TypeChar
:
rf
:=
&
nodefs
.
MemRegularFile
{}
rf
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
rf
,
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFCHR
}),
false
)
case
tar
.
TypeBlock
:
rf
:=
&
nodefs
.
MemRegularFile
{}
rf
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
rf
,
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFBLK
}),
false
)
case
tar
.
TypeDir
:
rf
:=
&
nodefs
.
MemRegularFile
{}
rf
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
rf
,
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
}),
false
)
case
tar
.
TypeFifo
:
rf
:=
&
nodefs
.
MemRegularFile
{}
rf
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
rf
,
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFIFO
}),
false
)
case
tar
.
TypeReg
,
tar
.
TypeRegA
:
df
:=
&
nodefs
.
MemRegularFile
{
Data
:
buf
.
Bytes
(),
}
HeaderToFileInfo
(
&
df
.
Attr
,
hdr
)
df
.
Attr
=
attr
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
df
,
nodefs
.
NodeAttr
{}),
false
)
default
:
log
.
Printf
(
"entry %q: unsupported type '%c'"
,
hdr
.
Name
,
hdr
.
Typeflag
)
}
}
}
...
...
zipfs/tarfs_test.go
View file @
1abae81d
...
...
@@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"syscall"
"testing"
"time"
...
...
@@ -20,6 +21,7 @@ import (
)
var
tarContents
=
map
[
string
]
string
{
"emptydir/"
:
""
,
"file.txt"
:
"content"
,
"dir/subfile.txt"
:
"other content"
,
}
...
...
@@ -48,14 +50,16 @@ func TestTar(t *testing.T) {
}
isLink
:=
filepath
.
Base
(
k
)
==
"link"
isDir
:=
strings
.
HasSuffix
(
k
,
"/"
)
if
isLink
{
h
.
Typeflag
=
tar
.
TypeSymlink
h
.
Linkname
=
v
}
else
if
isDir
{
h
.
Typeflag
=
tar
.
TypeDir
}
w
.
WriteHeader
(
h
)
if
!
isLink
{
if
!
isLink
&&
!
isDir
{
w
.
Write
([]
byte
(
v
))
}
}
...
...
@@ -89,9 +93,15 @@ func TestTar(t *testing.T) {
if
got
!=
want
{
t
.
Errorf
(
"Readlink: got %q want %q"
,
got
,
want
)
}
}
else
if
strings
.
HasSuffix
(
k
,
"/"
)
{
if
got
,
want
:=
st
.
Mode
,
uint32
(
syscall
.
S_IFDIR
|
0464
);
got
!=
want
{
t
.
Errorf
(
"dir %q: got mode %o, want %o"
,
k
,
got
,
want
)
}
}
else
{
if
got
,
want
:=
st
.
Mode
,
uint32
(
syscall
.
S_IFREG
|
0464
);
got
!=
want
{
t
.
Errorf
(
"
got mode %o, want %o"
,
got
,
want
)
t
.
Errorf
(
"
entry %q, got mode %o, want %o"
,
k
,
got
,
want
)
}
c
,
err
:=
ioutil
.
ReadFile
(
p
)
...
...
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