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
d1deed27
Commit
d1deed27
authored
Apr 04, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zipfs: fix and test tarfs
parent
74a78660
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
23 deletions
+125
-23
zipfs/tarfs.go
zipfs/tarfs.go
+18
-23
zipfs/tarfs_test.go
zipfs/tarfs_test.go
+107
-0
No files found.
zipfs/tarfs.go
View file @
d1deed27
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"compress/gzip"
"compress/gzip"
"context"
"context"
"io"
"io"
"log"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -30,20 +31,6 @@ func HeaderToFileInfo(out *fuse.Attr, h *tar.Header) {
...
@@ -30,20 +31,6 @@ func HeaderToFileInfo(out *fuse.Attr, h *tar.Header) {
out
.
SetTimes
(
&
h
.
AccessTime
,
&
h
.
ModTime
,
&
h
.
ChangeTime
)
out
.
SetTimes
(
&
h
.
AccessTime
,
&
h
.
ModTime
,
&
h
.
ChangeTime
)
}
}
type
TarFile
struct
{
data
[]
byte
tar
.
Header
}
func
(
f
*
TarFile
)
Stat
(
out
*
fuse
.
Attr
)
{
HeaderToFileInfo
(
out
,
&
f
.
Header
)
out
.
Mode
|=
syscall
.
S_IFREG
}
func
(
f
*
TarFile
)
Data
()
[]
byte
{
return
f
.
data
}
type
tarRoot
struct
{
type
tarRoot
struct
{
nodefs
.
Inode
nodefs
.
Inode
rc
io
.
ReadCloser
rc
io
.
ReadCloser
...
@@ -61,7 +48,9 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
...
@@ -61,7 +48,9 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
break
break
}
}
if
err
!=
nil
{
if
err
!=
nil
{
// handle error
log
.
Printf
(
"Add: %v"
,
err
)
// XXX handle error
break
}
}
if
hdr
.
Typeflag
==
'L'
{
if
hdr
.
Typeflag
==
'L'
{
...
@@ -83,9 +72,6 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
...
@@ -83,9 +72,6 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
io
.
Copy
(
buf
,
tr
)
io
.
Copy
(
buf
,
tr
)
df
:=
&
nodefs
.
MemRegularFile
{
Data
:
buf
.
Bytes
(),
}
dir
,
base
:=
filepath
.
Split
(
filepath
.
Clean
(
hdr
.
Name
))
dir
,
base
:=
filepath
.
Split
(
filepath
.
Clean
(
hdr
.
Name
))
p
:=
r
.
EmbeddedInode
()
p
:=
r
.
EmbeddedInode
()
...
@@ -95,15 +81,25 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
...
@@ -95,15 +81,25 @@ func (r *tarRoot) OnAdd(ctx context.Context) {
}
}
ch
:=
p
.
GetChild
(
comp
)
ch
:=
p
.
GetChild
(
comp
)
if
ch
==
nil
{
if
ch
==
nil
{
p
.
AddChild
(
comp
,
p
.
NewPersistentInode
(
ctx
,
ch
=
p
.
NewPersistentInode
(
ctx
,
&
nodefs
.
Inode
{},
&
nodefs
.
Inode
{},
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
}),
false
)
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
p
.
AddChild
(
comp
,
ch
,
false
)
}
}
p
=
ch
p
=
ch
}
}
HeaderToFileInfo
(
&
df
.
Attr
,
hdr
)
if
hdr
.
Typeflag
==
tar
.
TypeSymlink
{
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
df
,
nodefs
.
NodeAttr
{}),
false
)
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
&
nodefs
.
MemSymlink
{
Data
:
[]
byte
(
hdr
.
Linkname
),
},
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFLNK
}),
false
)
}
else
{
df
:=
&
nodefs
.
MemRegularFile
{
Data
:
buf
.
Bytes
(),
}
HeaderToFileInfo
(
&
df
.
Attr
,
hdr
)
p
.
AddChild
(
base
,
r
.
NewPersistentInode
(
ctx
,
df
,
nodefs
.
NodeAttr
{}),
false
)
}
}
}
}
}
...
@@ -121,7 +117,6 @@ func NewTarCompressedTree(name string, format string) (nodefs.InodeEmbedder, err
...
@@ -121,7 +117,6 @@ func NewTarCompressedTree(name string, format string) (nodefs.InodeEmbedder, err
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
f
.
Close
()
var
stream
io
.
ReadCloser
var
stream
io
.
ReadCloser
switch
format
{
switch
format
{
...
...
zipfs/tarfs_test.go
0 → 100644
View file @
d1deed27
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
zipfs
import
(
"archive/tar"
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/internal/testutil"
"github.com/hanwen/go-fuse/nodefs"
)
var
tarContents
=
map
[
string
]
string
{
"file.txt"
:
"content"
,
"dir/subfile.txt"
:
"other content"
,
}
type
addClose
struct
{
io
.
Reader
}
func
(
c
*
addClose
)
Close
()
error
{
return
nil
}
func
TestTar
(
t
*
testing
.
T
)
{
buf
:=
&
bytes
.
Buffer
{}
w
:=
tar
.
NewWriter
(
buf
)
now
:=
time
.
Now
()
for
k
,
v
:=
range
tarContents
{
h
:=
&
tar
.
Header
{
Name
:
k
,
Size
:
int64
(
len
(
v
)),
Mode
:
0464
,
Uid
:
42
,
Gid
:
42
,
ModTime
:
now
,
}
isLink
:=
filepath
.
Base
(
k
)
==
"link"
if
isLink
{
h
.
Typeflag
=
tar
.
TypeSymlink
h
.
Linkname
=
v
}
w
.
WriteHeader
(
h
)
if
!
isLink
{
w
.
Write
([]
byte
(
v
))
}
}
w
.
Close
()
root
:=
&
tarRoot
{
rc
:
&
addClose
{
buf
}}
mnt
:=
testutil
.
TempDir
()
defer
os
.
Remove
(
mnt
)
opts
:=
&
nodefs
.
Options
{}
opts
.
Debug
=
true
s
,
err
:=
nodefs
.
Mount
(
mnt
,
root
,
opts
)
if
err
!=
nil
{
t
.
Errorf
(
"Mount: %v"
,
err
)
}
defer
s
.
Unmount
()
for
k
,
want
:=
range
tarContents
{
p
:=
filepath
.
Join
(
mnt
,
k
)
var
st
syscall
.
Stat_t
if
err
:=
syscall
.
Lstat
(
p
,
&
st
);
err
!=
nil
{
t
.
Fatalf
(
"Stat %q: %v"
,
p
,
err
)
}
if
filepath
.
Base
(
k
)
==
"link"
{
got
,
err
:=
os
.
Readlink
(
p
)
if
err
!=
nil
{
t
.
Fatalf
(
"Readlink: %v"
,
err
)
}
if
got
!=
want
{
t
.
Errorf
(
"Readlink: got %q want %q"
,
got
,
want
)
}
}
else
{
if
got
,
want
:=
st
.
Mode
,
uint32
(
syscall
.
S_IFREG
|
0464
);
got
!=
want
{
t
.
Errorf
(
"got mode %o, want %o"
,
got
,
want
)
}
c
,
err
:=
ioutil
.
ReadFile
(
p
)
if
err
!=
nil
{
t
.
Errorf
(
"read %q: %v"
,
k
,
err
)
got
:=
string
(
c
)
if
got
!=
want
{
t
.
Errorf
(
"file %q: got %q, want %q"
,
k
,
got
,
want
)
}
}
}
}
}
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