mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
create files correctly!
This commit is contained in:
parent
793dd81ca2
commit
7ca5052942
|
@ -21,6 +21,9 @@ type Dir struct {
|
||||||
wfs *WFS
|
wfs *WFS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = fs.Node(&Dir{})
|
||||||
|
var _ = fs.HandleReadDirAller(&Dir{})
|
||||||
|
|
||||||
func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
||||||
attr.Mode = os.ModeDir | 0777
|
attr.Mode = os.ModeDir | 0777
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -23,6 +23,7 @@ var _ = fs.HandleReadAller(&File{})
|
||||||
// var _ = fs.HandleReader(&File{})
|
// var _ = fs.HandleReader(&File{})
|
||||||
var _ = fs.HandleFlusher(&File{})
|
var _ = fs.HandleFlusher(&File{})
|
||||||
var _ = fs.HandleWriter(&File{})
|
var _ = fs.HandleWriter(&File{})
|
||||||
|
var _ = fs.HandleReleaser(&File{})
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Chunks []*filer_pb.FileChunk
|
Chunks []*filer_pb.FileChunk
|
||||||
|
@ -49,6 +50,7 @@ func (file *File) Attr(context context.Context, attr *fuse.Attr) error {
|
||||||
glog.V(1).Infof("read file size: %v", request)
|
glog.V(1).Infof("read file size: %v", request)
|
||||||
resp, err := client.GetFileAttributes(context, request)
|
resp, err := client.GetFileAttributes(context, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
glog.V(0).Infof("read file attributes %v: %v", request, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,13 +69,17 @@ func (file *File) Attr(context context.Context, attr *fuse.Attr) error {
|
||||||
attr.Mtime = time.Unix(attributes.Mtime, 0)
|
attr.Mtime = time.Unix(attributes.Mtime, 0)
|
||||||
attr.Gid = attributes.Gid
|
attr.Gid = attributes.Gid
|
||||||
attr.Uid = attributes.Uid
|
attr.Uid = attributes.Uid
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (file *File) ReadAll(ctx context.Context) (content []byte, err error) {
|
func (file *File) ReadAll(ctx context.Context) (content []byte, err error) {
|
||||||
|
|
||||||
|
// fmt.Printf("read all file %+v/%v\n", file.dir.Path, file.Name)
|
||||||
|
|
||||||
if len(file.Chunks) == 0 {
|
if len(file.Chunks) == 0 {
|
||||||
|
glog.V(0).Infof("empty file %v/%v", file.dir.Path, file.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +115,12 @@ func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
|
||||||
func (file *File) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
func (file *File) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
||||||
// fflush works at file level
|
// fflush works at file level
|
||||||
// send the data to the OS
|
// send the data to the OS
|
||||||
fmt.Printf("flush file %+v\n", req)
|
glog.V(3).Infof("file flush %v", req)
|
||||||
|
|
||||||
|
if len(file.Chunks) == 0 {
|
||||||
|
glog.V(2).Infof("file flush skipping empty %v", req)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err := file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
err := file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
|
@ -134,7 +145,7 @@ func (file *File) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
||||||
|
|
||||||
func (file *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
|
func (file *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
|
||||||
// write the request to volume servers
|
// write the request to volume servers
|
||||||
fmt.Printf("write file %+v\n", req)
|
// fmt.Printf("write file %+v\n", req)
|
||||||
|
|
||||||
var fileId, host string
|
var fileId, host string
|
||||||
|
|
||||||
|
@ -178,5 +189,14 @@ func (file *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.
|
||||||
Mtime: time.Now().UnixNano(),
|
Mtime: time.Now().UnixNano(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
resp.Size = int(uploadResult.Size)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (file *File) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
|
||||||
|
|
||||||
|
// fmt.Printf("release file %+v\n", req)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue