Commit 8704b7c6 authored by Fazlul Shahriar's avatar Fazlul Shahriar Committed by Han-Wen Nienhuys

zipfs: take care of couple of TODO (better error handling)

parent fbf3de98
...@@ -18,13 +18,16 @@ func main() { ...@@ -18,13 +18,16 @@ func main() {
flag.Parse() flag.Parse()
if flag.NArg() < 2 { if flag.NArg() < 2 {
// TODO - where to get program name? fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
fmt.Println("usage: main MOUNTPOINT ZIP-FILE")
os.Exit(2) os.Exit(2)
} }
var fs fuse.FileSystem var fs fuse.FileSystem
fs = zipfs.NewZipArchiveFileSystem(flag.Arg(1)) fs, err := zipfs.NewZipArchiveFileSystem(flag.Arg(1))
if err != nil {
fmt.Fprintf(os.Stderr, "NewZipArchiveFileSystem failed: %v\n", err)
os.Exit(1)
}
debugFs := fuse.NewFileSystemDebug() debugFs := fuse.NewFileSystemDebug()
if *latencies { if *latencies {
......
...@@ -42,10 +42,10 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f ...@@ -42,10 +42,10 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f
zipFile := string(nameBytes) zipFile := string(nameBytes)
zipFile = strings.Trim(zipFile, "\n ") zipFile = strings.Trim(zipFile, "\n ")
fs := NewZipArchiveFileSystem(zipFile) fs, err := NewZipArchiveFileSystem(zipFile)
if fs == nil { if err != nil {
// TODO // TODO
log.Println("NewZipArchiveFileSystem returned nil") log.Println("NewZipArchiveFileSystem failed:", err)
me.zfs.pendingZips[me.Basename] = false, false me.zfs.pendingZips[me.Basename] = false, false
return 0, fuse.ENOSYS return 0, fuse.ENOSYS
} }
......
...@@ -100,18 +100,18 @@ func zipFilesToTree(files []*zip.File) *ZipDirTree { ...@@ -100,18 +100,18 @@ func zipFilesToTree(files []*zip.File) *ZipDirTree {
return t return t
} }
func NewZipArchiveFileSystem(name string) *ZipArchiveFileSystem { // NewZipArchiveFileSystem creates a new file-system for the
// zip file named name.
func NewZipArchiveFileSystem(name string) (*ZipArchiveFileSystem, os.Error) {
z := new(ZipArchiveFileSystem) z := new(ZipArchiveFileSystem)
r, err := zip.OpenReader(name) r, err := zip.OpenReader(name)
if err != nil { if err != nil {
// TODO - return os.Error instead. return nil, err
log.Println("NewZipArchiveFileSystem(): " + err.String())
return nil
} }
z.ZipFileName = name z.ZipFileName = name
z.zipReader = r z.zipReader = r
z.tree = zipFilesToTree(r.File) z.tree = zipFilesToTree(r.File)
return z return z, nil
} }
const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700 const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700
......
...@@ -9,7 +9,10 @@ import ( ...@@ -9,7 +9,10 @@ import (
func TestZipFs(t *testing.T) { func TestZipFs(t *testing.T) {
wd, err := os.Getwd() wd, err := os.Getwd()
CheckSuccess(err) CheckSuccess(err)
zfs := NewZipArchiveFileSystem(wd + "/test.zip") zfs, err := NewZipArchiveFileSystem(wd + "/test.zip")
if err != nil {
t.Error("NewZipArchiveFileSystem failed:", err)
}
connector := fuse.NewFileSystemConnector(zfs) connector := fuse.NewFileSystemConnector(zfs)
mountPoint := fuse.MakeTempDir() mountPoint := fuse.MakeTempDir()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment