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
Levin Zimmermann
go-fuse
Commits
0a3f35a3
Commit
0a3f35a3
authored
May 15, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create NewTarTree() and accept .tar.gz and .tar.bz2.
parent
0ec6d90d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
167 additions
and
21 deletions
+167
-21
example/zipfs/main.go
example/zipfs/main.go
+2
-2
zipfs/Makefile
zipfs/Makefile
+1
-0
zipfs/memtree.go
zipfs/memtree.go
+8
-8
zipfs/multizip.go
zipfs/multizip.go
+6
-6
zipfs/tarfs.go
zipfs/tarfs.go
+124
-0
zipfs/zipfs.go
zipfs/zipfs.go
+25
-4
zipfs/zipfs_test.go
zipfs/zipfs_test.go
+1
-1
No files found.
example/zipfs/main.go
View file @
0a3f35a3
...
...
@@ -23,9 +23,9 @@ func main() {
}
var
fs
fuse
.
FileSystem
fs
,
err
:=
zipfs
.
New
Zip
ArchiveFileSystem
(
flag
.
Arg
(
1
))
fs
,
err
:=
zipfs
.
NewArchiveFileSystem
(
flag
.
Arg
(
1
))
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"New
Zip
ArchiveFileSystem failed: %v
\n
"
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"NewArchiveFileSystem failed: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
debugFs
:=
fuse
.
NewFileSystemDebug
()
...
...
zipfs/Makefile
View file @
0a3f35a3
...
...
@@ -6,6 +6,7 @@ DEPS=../fuse
GOFILES
=
zipfs.go
\
multizip.go
\
tarfs.go
\
memtree.go
include
$(GOROOT)/src/Make.pkg
...
...
zipfs/memtree.go
View file @
0a3f35a3
...
...
@@ -10,8 +10,8 @@ import (
type
MemFile
interface
{
Stat
()
*
os
.
FileInfo
Data
()
[]
byte
Stat
()
*
os
.
FileInfo
Data
()
[]
byte
}
type
MemTree
struct
{
...
...
@@ -76,7 +76,7 @@ func (me *MemTree) FindDir(name string) *MemTree {
////////////////////////////////////////////////////////////////
type
MemTreeFileSystem
struct
{
tree
*
MemTree
tree
*
MemTree
fuse
.
DefaultFileSystem
}
...
...
@@ -126,18 +126,18 @@ func (me *MemTreeFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, co
if
dir
==
nil
{
panic
(
"dir"
)
}
stream
=
make
(
chan
fuse
.
DirEntry
,
len
(
dir
.
files
)
+
len
(
dir
.
subdirs
))
for
k
,
_
:=
range
dir
.
files
{
stream
<-
fuse
.
DirEntry
{
Name
:
k
,
Mode
:
mem_FILEMODE
,
Name
:
k
,
Mode
:
mem_FILEMODE
,
}
}
for
k
,
_
:=
range
dir
.
subdirs
{
stream
<-
fuse
.
DirEntry
{
Name
:
k
,
Mode
:
mem_DIRMODE
,
Name
:
k
,
Mode
:
mem_DIRMODE
,
}
}
close
(
stream
)
...
...
zipfs/multizip.go
View file @
0a3f35a3
...
...
@@ -43,10 +43,10 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f
zipFile
:=
string
(
nameBytes
)
zipFile
=
strings
.
Trim
(
zipFile
,
"
\n
"
)
fs
,
err
:=
New
Zip
ArchiveFileSystem
(
zipFile
)
fs
,
err
:=
NewArchiveFileSystem
(
zipFile
)
if
err
!=
nil
{
// TODO
log
.
Println
(
"NewZipArchiveFileSystem failed
:"
,
err
)
log
.
Println
(
"NewZipArchiveFileSystem failed
."
)
me
.
zfs
.
pendingZips
[
me
.
Basename
]
=
false
,
false
return
0
,
fuse
.
ENOSYS
}
...
...
@@ -73,10 +73,10 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f
// reference to the FileSystemConnector to be able to execute
// mounts.
type
MultiZipFs
struct
{
Connector
*
fuse
.
FileSystemConnector
lock
sync
.
RWMutex
zips
map
[
string
]
*
MemTreeFileSystem
pendingZips
map
[
string
]
bool
Connector
*
fuse
.
FileSystemConnector
lock
sync
.
RWMutex
zips
map
[
string
]
*
MemTreeFileSystem
pendingZips
map
[
string
]
bool
dirZipFileMap
map
[
string
]
string
fuse
.
DefaultFileSystem
...
...
zipfs/tarfs.go
0 → 100644
View file @
0a3f35a3
package
zipfs
import
(
"archive/tar"
"bytes"
"compress/bzip2"
"compress/gzip"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"syscall"
)
var
_
=
fmt
.
Println
// TODO - handle symlinks.
func
HeaderToFileInfo
(
h
*
tar
.
Header
)
*
os
.
FileInfo
{
return
&
os
.
FileInfo
{
Name
:
h
.
Name
,
Mode
:
uint32
(
h
.
Mode
),
Uid
:
h
.
Uid
,
Gid
:
h
.
Gid
,
Size
:
h
.
Size
,
Mtime_ns
:
h
.
Mtime
,
//Linkname: h.Linkname ,
Atime_ns
:
h
.
Atime
,
Ctime_ns
:
h
.
Ctime
,
}
}
type
TarFile
struct
{
data
[]
byte
tar
.
Header
}
func
(
me
*
TarFile
)
Stat
()
*
os
.
FileInfo
{
fi
:=
HeaderToFileInfo
(
&
me
.
Header
)
fi
.
Mode
|=
syscall
.
S_IFREG
return
fi
}
func
(
me
*
TarFile
)
Data
()
[]
byte
{
return
me
.
data
}
func
NewTarTree
(
r
io
.
Reader
)
*
MemTree
{
tree
:=
NewMemTree
()
tr
:=
tar
.
NewReader
(
r
)
var
longName
*
string
for
{
hdr
,
err
:=
tr
.
Next
()
if
err
==
os
.
EOF
{
// end of tar archive
break
}
if
err
!=
nil
{
// handle error
}
if
hdr
.
Typeflag
==
'L'
{
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
io
.
Copy
(
buf
,
tr
)
s
:=
buf
.
String
()
longName
=
&
s
continue
}
if
longName
!=
nil
{
hdr
.
Name
=
*
longName
longName
=
nil
}
comps
:=
strings
.
Split
(
filepath
.
Clean
(
hdr
.
Name
),
"/"
,
-
1
)
base
:=
""
if
!
strings
.
HasSuffix
(
hdr
.
Name
,
"/"
)
{
base
=
comps
[
len
(
comps
)
-
1
]
comps
=
comps
[
:
len
(
comps
)
-
1
]
}
parent
:=
tree
for
_
,
c
:=
range
comps
{
parent
=
parent
.
FindDir
(
c
)
}
buf
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
hdr
.
Size
))
io
.
Copy
(
buf
,
tr
)
if
base
!=
""
{
b
:=
buf
.
Bytes
()
parent
.
files
[
base
]
=
&
TarFile
{
Header
:
*
hdr
,
data
:
b
,
}
}
}
return
tree
}
func
NewTarCompressedTree
(
name
string
,
format
string
)
(
*
MemTree
,
os
.
Error
)
{
f
,
err
:=
os
.
Open
(
name
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
var
stream
io
.
Reader
switch
format
{
case
"gz"
:
unzip
,
err
:=
gzip
.
NewReader
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
defer
unzip
.
Close
()
stream
=
unzip
case
"bz2"
:
unzip
:=
bzip2
.
NewReader
(
f
)
stream
=
unzip
}
return
NewTarTree
(
stream
),
nil
}
zipfs/zipfs.go
View file @
0a3f35a3
...
...
@@ -23,7 +23,7 @@ func (me *ZipFile) Stat() *os.FileInfo {
Size
:
int64
(
me
.
File
.
UncompressedSize
),
}
}
func
(
me
*
ZipFile
)
Data
()
[]
byte
{
data
:=
make
([]
byte
,
me
.
UncompressedSize
)
zf
:=
(
*
me
)
...
...
@@ -72,11 +72,32 @@ func zipFilesToTree(files []*zip.File) *MemTree {
// NewZipArchiveFileSystem creates a new file-system for the
// zip file named name.
func
NewZip
ArchiveFileSystem
(
name
string
)
(
*
MemTreeFileSystem
,
os
.
Error
)
{
func
NewZip
Tree
(
name
string
)
(
*
MemTree
,
os
.
Error
)
{
r
,
err
:=
zip
.
OpenReader
(
name
)
if
err
!=
nil
{
return
nil
,
err
}
z
:=
NewMemTreeFileSystem
(
zipFilesToTree
(
r
.
File
))
return
z
,
nil
return
zipFilesToTree
(
r
.
File
),
nil
}
func
NewArchiveFileSystem
(
name
string
)
(
fs
*
MemTreeFileSystem
,
err
os
.
Error
)
{
var
tree
*
MemTree
if
strings
.
HasSuffix
(
name
,
".zip"
)
{
tree
,
err
=
NewZipTree
(
name
)
}
if
strings
.
HasSuffix
(
name
,
".tar.gz"
)
{
tree
,
err
=
NewTarCompressedTree
(
name
,
"gz"
)
}
if
strings
.
HasSuffix
(
name
,
".tar.bz2"
)
{
tree
,
err
=
NewTarCompressedTree
(
name
,
"bz2"
)
}
if
err
!=
nil
{
return
nil
,
err
}
if
tree
==
nil
{
return
nil
,
os
.
NewError
(
fmt
.
Sprintf
(
"Unknown type for %v"
,
name
))
}
return
NewMemTreeFileSystem
(
tree
),
nil
}
zipfs/zipfs_test.go
View file @
0a3f35a3
...
...
@@ -9,7 +9,7 @@ import (
func
TestZipFs
(
t
*
testing
.
T
)
{
wd
,
err
:=
os
.
Getwd
()
CheckSuccess
(
err
)
zfs
,
err
:=
New
Zip
ArchiveFileSystem
(
wd
+
"/test.zip"
)
zfs
,
err
:=
NewArchiveFileSystem
(
wd
+
"/test.zip"
)
if
err
!=
nil
{
t
.
Error
(
"NewZipArchiveFileSystem failed:"
,
err
)
}
...
...
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