Exemplo n.º 1
0
Arquivo: fs.go Projeto: rnd-ua/scope
func (p dir) Open(path string) (io.ReadWriteCloser, error) {
	if path == "/" {
		return nil, fmt.Errorf("I'm a directory!")
	}

	head, tail := split(path)
	fs, ok := p.entries[head]
	if !ok {
		return nil, fmt.Errorf("Not found: %s", path)
	}

	return fs.Open(tail)
}
Exemplo n.º 2
0
Arquivo: proc.go Projeto: rnd-ua/scope
			}

			// We want sockets only.
			if statT.Mode&syscall.S_IFMT != syscall.S_IFSOCK {
				continue
			}
			if proc == nil {
				proc = &Proc{
					PID:  uint(p.PID),
					Name: p.Name,
				}
			}
			res[statT.Ino] = proc
		}
	})

	return res, nil
}

// readFile reads an arbitrary file into a buffer. It's a variable so it can
// be overwritten for benchmarks. That's bad practice and we should change it
// to be a dependency.
var readFile = func(filename string, buf *bytes.Buffer) (int64, error) {
	f, err := fs.Open(filename)
	if err != nil {
		return -1, err
	}
	defer f.Close()
	return buf.ReadFrom(f)
}