Beispiel #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
	}
	size, reader, err := objectsReader.NextObject()
	if err != nil {
		return err
	}
	defer reader.Close()
	filename := fmt.Sprintf("%s.%x", baseOutputFilename, hashVal)
	file, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer file.Close()
	ncopied, err := io.CopyN(file, reader, int64(size))
	if err != nil {
		return err
	}
	if uint64(ncopied) != size {
		return errors.New(fmt.Sprintf("copied: %d, wanted: %d", ncopied, size))
	}
	return nil
}
Beispiel #2
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
	}
	size, reader, err := objectsReader.NextObject()
	if err != nil {
		return err
	}
	defer reader.Close()
	filename := fmt.Sprintf("%s.%x", baseOutputFilename, hashVal)
	return fsutil.CopyToFile(filename, reader, int64(size))
}
Beispiel #3
0
func getObjects(objSrv objectserver.ObjectServer,
	hashesFilename, outputDirectory string) error {
	hashesFile, err := os.Open(hashesFilename)
	if err != nil {
		return err
	}
	defer hashesFile.Close()
	scanner := bufio.NewScanner(hashesFile)
	var hashes []hash.Hash
	for scanner.Scan() {
		hashval, err := objectcache.FilenameToHash(scanner.Text())
		if err != nil {
			return err
		}
		hashes = append(hashes, hashval)
	}
	if err := scanner.Err(); err != nil {
		return err
	}
	objectsReader, err := objSrv.GetObjects(hashes)
	if err != nil {
		return err
	}
	defer objectsReader.Close()
	tmpDirname := outputDirectory + "~"
	if err := os.Mkdir(tmpDirname, syscall.S_IRWXU); err != nil {
		return err
	}
	defer os.RemoveAll(tmpDirname)
	for _, hash := range hashes {
		length, reader, err := objectsReader.NextObject()
		if err != nil {
			return err
		}
		err = readOne(tmpDirname, hash, length, reader)
		reader.Close()
		if err != nil {
			return err
		}
	}
	return os.Rename(tmpDirname, outputDirectory)
}