1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 18:13:54 +08:00

address most of CR comments

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-09-02 10:12:04 -07:00
parent 9bbd9b061d
commit 4bcacc5936
3 changed files with 21 additions and 31 deletions

View File

@ -12,6 +12,8 @@ const (
multipartFormdataType = "multipart/form-data" multipartFormdataType = "multipart/form-data"
multipartMixedType = "multipart/mixed" multipartMixedType = "multipart/mixed"
applicationSymlink = "application/symlink"
contentTypeHeader = "Content-Type" contentTypeHeader = "Content-Type"
) )
@ -31,7 +33,7 @@ func NewFileFromPart(part *multipart.Part) (File, error) {
} }
contentType := part.Header.Get(contentTypeHeader) contentType := part.Header.Get(contentTypeHeader)
if contentType == "symlink" { if contentType == applicationSymlink {
out, err := ioutil.ReadAll(part) out, err := ioutil.ReadAll(part)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -69,8 +69,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
if s, ok := file.(*files.Symlink); ok { if s, ok := file.(*files.Symlink); ok {
mfr.currentFile = s mfr.currentFile = s
// TODO(why): this is a hack. pick a real contentType contentType = "application/symlink"
contentType = "symlink"
} else if file.IsDirectory() { } else if file.IsDirectory() {
// if file is a directory, create a multifilereader from it // if file is a directory, create a multifilereader from it
// (using 'multipart/mixed') // (using 'multipart/mixed')

View File

@ -8,7 +8,6 @@ import (
"io" "io"
"os" "os"
"syscall" "syscall"
"time"
fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse" fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs" fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
@ -60,8 +59,6 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
log.Error("RESOLVE: ", name)
ctx, _ = context.WithTimeout(ctx, time.Second/2)
nd, err := s.Ipfs.Resolver.ResolvePath(ctx, path.Path(name)) nd, err := s.Ipfs.Resolver.ResolvePath(ctx, path.Path(name))
if err != nil { if err != nil {
// todo: make this error more versatile. // todo: make this error more versatile.
@ -100,35 +97,27 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
} }
switch s.cached.GetType() { switch s.cached.GetType() {
case ftpb.Data_Directory: case ftpb.Data_Directory:
*a = fuse.Attr{ a.Mode = os.ModeDir | 0555
Mode: os.ModeDir | 0555, a.Uid = uint32(os.Getuid())
Uid: uint32(os.Getuid()), a.Gid = uint32(os.Getgid())
Gid: uint32(os.Getgid()),
}
case ftpb.Data_File: case ftpb.Data_File:
size := s.cached.GetFilesize() size := s.cached.GetFilesize()
*a = fuse.Attr{ a.Mode = 0444
Mode: 0444, a.Size = uint64(size)
Size: uint64(size), a.Blocks = uint64(len(s.Nd.Links))
Blocks: uint64(len(s.Nd.Links)), a.Uid = uint32(os.Getuid())
Uid: uint32(os.Getuid()), a.Gid = uint32(os.Getgid())
Gid: uint32(os.Getgid()),
}
case ftpb.Data_Raw: case ftpb.Data_Raw:
*a = fuse.Attr{ a.Mode = 0444
Mode: 0444, a.Size = uint64(len(s.cached.GetData()))
Size: uint64(len(s.cached.GetData())), a.Blocks = uint64(len(s.Nd.Links))
Blocks: uint64(len(s.Nd.Links)), a.Uid = uint32(os.Getuid())
Uid: uint32(os.Getuid()), a.Gid = uint32(os.Getgid())
Gid: uint32(os.Getgid()),
}
case ftpb.Data_Symlink: case ftpb.Data_Symlink:
*a = fuse.Attr{ a.Mode = 0777 | os.ModeSymlink
Mode: 0777 | os.ModeSymlink, a.Size = uint64(len(s.cached.GetData()))
Size: uint64(len(s.cached.GetData())), a.Uid = uint32(os.Getuid())
Uid: uint32(os.Getuid()), a.Gid = uint32(os.Getgid())
Gid: uint32(os.Getgid()),
}
default: default:
return fmt.Errorf("Invalid data type - %s", s.cached.GetType()) return fmt.Errorf("Invalid data type - %s", s.cached.GetType())