2015-11-20 04:23:44 +03:00
|
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-01-24 08:16:53 +03:00
|
|
|
"archive/zip"
|
2015-11-20 04:23:44 +03:00
|
|
|
"bazil.org/fuse"
|
|
|
|
"bazil.org/fuse/fs"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Encapsulates state and operations for a virtual file inside zip archive on HDFS file system
|
|
|
|
type ZipFile struct {
|
2016-01-13 23:25:22 +03:00
|
|
|
Attrs Attrs
|
|
|
|
zipFile *zip.File
|
|
|
|
FileSystem *FileSystem
|
2015-11-20 04:23:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that *Dir implements necesary FUSE interfaces
|
|
|
|
var _ fs.Node = (*ZipFile)(nil)
|
|
|
|
var _ fs.NodeOpener = (*ZipFile)(nil)
|
|
|
|
|
|
|
|
// Responds on FUSE Attr request to retrieve file attributes
|
|
|
|
func (this *ZipFile) Attr(ctx context.Context, fuseAttr *fuse.Attr) error {
|
|
|
|
return this.Attrs.Attr(fuseAttr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Responds on FUSE Open request for a file inside zip archive
|
|
|
|
func (this *ZipFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
|
|
|
|
contentStream, err := this.zipFile.Open()
|
|
|
|
if err != nil {
|
2017-05-15 23:47:40 +03:00
|
|
|
Error.Println("Opening [", this.Attrs.Name, "], error: ", err)
|
2015-11-20 04:23:44 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// reporting to FUSE that the stream isn't seekable
|
|
|
|
resp.Flags |= fuse.OpenNonSeekable
|
|
|
|
return NewZipFileHandle(contentStream), nil
|
|
|
|
}
|