Exemple #1
0
func attr(aname string, v1 value) (value, error) {
	fname, ok := v1.(string)
	if !ok {
		return nil, errors.New("not a file name")
	}
	d, err := nsutil.Stat(fname)
	if err != nil {
		return nil, err
	}
	if aname == "r" {
		return d.Int("mode")&0444 != 0, nil
	}
	if aname == "w" {
		return d.Int("mode")&0222 != 0, nil
	}
	if aname == "x" {
		return d.Int("mode")&0111 != 0, nil
	}
	if aname == "mode" {
		return fmt.Sprintf("0%o", d.Int("mode")&0777), nil
	}
	if aname == "size" {
		return int64(d.Int64("size")), nil
	}
	if aname == "mtime" {
		return d.Time("mtime"), nil
	}
	return d[aname], nil
}
Exemple #2
0
// runs here
func runCd(x *xEnv, argv ...string) error {
	opts := opt.New("")
	app.Dprintf("cd %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	if len(args) != 0 {
		opts.Usage()
		return dbg.ErrUsage
	}
	m, ok := <-app.In()
	if !ok {
		err = cerror(app.In())
		app.Warn("%s", err)
		return err
	}
	d, ok := m.(zx.Dir)
	if !ok {
		b, ok := m.([]byte)
		if !ok {
			app.Warn("%s", dbg.ErrNotDir)
			return dbg.ErrNotDir
		}
		s := string(b)
		d, err = nsutil.Stat(s)
		if err != nil {
			app.Warn("%s: %s", s, err)
			return err
		}
	}
	if d["type"] != "d" {
		app.Warn("%s: %s", d["path"], dbg.ErrNotDir)
		return dbg.ErrNotDir
	}
	app.Cd(d["path"])
	out := app.Out()
	if out != nil {
		out <- d
	}
	return nil
}