Exemple #1
0
func (plan *PatchPlan) appendFilePlan(srcFile *fs.File, dstPath string) error {
	match, err := MatchIndex(plan.srcStore.Index(), plan.dstStore.Resolve(dstPath))
	if match == nil {
		return err
	}
	match.SrcSize = srcFile.Size

	// Create a local temporary file in which to effect changes
	localTemp := &LocalTemp{
		Path: &LocalPath{
			LocalStore: plan.dstStore,
			RelPath:    dstPath},
		Size: match.SrcSize}
	plan.Cmds = append(plan.Cmds, localTemp)

	for _, blockMatch := range match.BlockMatches {
		plan.Cmds = append(plan.Cmds, &LocalTempCopy{
			Temp:        localTemp,
			LocalOffset: blockMatch.SrcBlock.Offset(),
			TempOffset:  blockMatch.DstOffset,
			Length:      int64(fs.BLOCKSIZE)})
	}

	for _, srcRange := range match.NotMatched() {
		plan.Cmds = append(plan.Cmds, &SrcTempCopy{
			Temp:       localTemp,
			SrcStrong:  srcFile.Strong(),
			SrcOffset:  srcRange.From,
			TempOffset: srcRange.From,
			Length:     srcRange.To - srcRange.From})
	}

	// Replace dst file with temp
	plan.Cmds = append(plan.Cmds, &ReplaceWithTemp{Temp: localTemp})

	return nil
}