Example #1
0
File: main.go Project: sbinet/romba
func lookup(cmd *commander.Command, args []string) {
	if len(args) == 0 {
		return
	}

	for _, arg := range args {
		exists, err := archive.PathExists(arg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to stat %s: %v\n", arg, err)
			os.Exit(1)
		}
		if exists {
			hh, err := archive.HashesForFile(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to compute hashes for %s: %v\n", arg, err)
				os.Exit(1)
			}

			found, err := lookupByHash(hh.Sha1)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by sha1 hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
			if found {
				continue
			}
			found, err = lookupByHash(hh.Md5)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by md5 hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
			if found {
				continue
			}

			found, err = lookupByHash(hh.Crc)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by crc hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
		} else {
			hash, err := hex.DecodeString(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to decode hex string %s: %v\n", arg, err)
				os.Exit(1)
			}
			_, err = lookupByHash(hash)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
		}
	}

}
Example #2
0
func findINI() (string, error) {
	u, err := user.Current()
	if err != nil {
		return "", err
	}
	path := "romba.ini"
	exists, err := archive.PathExists(path)
	if err != nil {
		return "", err
	}
	if exists {
		return path, nil
	}

	path = filepath.Join(u.HomeDir, ".romba", "romba.ini")
	exists, err = archive.PathExists(path)
	if err != nil {
		return "", err
	}
	if exists {
		return path, nil
	}
	return "", fmt.Errorf("couldn't find romba.ini")
}