Ejemplo n.º 1
0
func getObject(objSrv objectserver.ObjectServer, hashVal hash.Hash,
	baseOutputFilename string) error {
	hashes := make([]hash.Hash, 1)
	hashes[0] = hashVal
	objectsReader, err := objSrv.GetObjects(hashes)
	if err != nil {
		return err
	}
	defer objectsReader.Close()
	size, reader, err := objectsReader.NextObject()
	if err != nil {
		return err
	}
	defer reader.Close()
	filename := fmt.Sprintf("%s.%x", baseOutputFilename, hashVal)
	return fsutil.CopyToFile(filename, filePerms, reader, size)
}
Ejemplo n.º 2
0
func checkObjectSubcommand(objSrv objectserver.ObjectServer, args []string) {
	hashes := make([]hash.Hash, 1)
	var err error
	hashes[0], err = objectcache.FilenameToHash(args[0])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing hash\t%s\n", err)
		os.Exit(2)
	}
	objectSizes, err := objSrv.CheckObjects(hashes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error checking object\t%s\n", err)
		os.Exit(2)
	}
	if objectSizes[0] > 0 {
		os.Exit(0)
	} else {
		os.Exit(1)
	}
}