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() {
flag.Parse()
if flag.NArg() < 2 {
// TODO - where to get program name?
fmt.Println("usage: main MOUNTPOINT ZIP-FILE")
fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
os.Exit(2)
}
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()
if *latencies {
......
......@@ -42,10 +42,10 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f
zipFile := string(nameBytes)
zipFile = strings.Trim(zipFile, "\n ")
fs := NewZipArchiveFileSystem(zipFile)
if fs == nil {
fs, err := NewZipArchiveFileSystem(zipFile)
if err != nil {
// TODO
log.Println("NewZipArchiveFileSystem returned nil")
log.Println("NewZipArchiveFileSystem failed:", err)
me.zfs.pendingZips[me.Basename] = false, false
return 0, fuse.ENOSYS
}
......
......@@ -100,18 +100,18 @@ func zipFilesToTree(files []*zip.File) *ZipDirTree {
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)
r, err := zip.OpenReader(name)
if err != nil {
// TODO - return os.Error instead.
log.Println("NewZipArchiveFileSystem(): " + err.String())
return nil
return nil, err
}
z.ZipFileName = name
z.zipReader = r
z.tree = zipFilesToTree(r.File)
return z
return z, nil
}
const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700
......
......@@ -9,7 +9,10 @@ import (
func TestZipFs(t *testing.T) {
wd, err := os.Getwd()
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)
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