~mkhl/xplor

fcbf98df302a69ef4d6e0fea6ed600d4106687ce — Martin Kühl 11 months ago 0cb1722
Reject non-directories
1 files changed, 10 insertions(+), 4 deletions(-)

M xplor.go
M xplor.go => xplor.go +10 -4
@@ 75,15 75,21 @@ func findRoot() error {
		root, err = os.Getwd()
		return err
	case 1: // start at path
		var err error
		root = filepath.Clean(flag.Arg(0))
		if filepath.IsAbs(root) {
			return nil
		if !filepath.IsAbs(root) {
			root, err = filepath.Abs(root)
			if err != nil {
				return err
			}
		}
		cwd, err := os.Getwd()
		info, err := os.Stat(root)
		if err != nil {
			return err
		}
		root = filepath.Join(cwd, root)
		if !info.IsDir() {
			return fmt.Errorf("%s: Not a directory", root)
		}
		return nil
	default:
		usage()