// Finalize flushes the mfs root directory and returns the mfs root node.
323821
func (adder *Adder) Finalize() (ipld.Node, error) {
	mr, err := adder.mfsRoot()
	if err != nil {
		return nil, err
	}
	var root mfs.FSNode
	rootdir := mr.GetDirectory()
	root = rootdir

	err = root.Flush()
	if err != nil {
		return nil, err
	}

	var name string
	if !adder.Wrap {
		children, err := rootdir.ListNames(adder.ctx)
		if err != nil {
			return nil, err
		}

		if len(children) == 0 {
			return nil, fmt.Errorf("expected at least one child dir, got none")
		}

		// Replace root with the first child
		name = children[0]
		root, err = rootdir.Child(name)
		if err != nil {
			return nil, err
		}
	}

	err = adder.outputDirs(name, root)
	if err != nil {
		return nil, err
	}

	err = mr.Close()
	if err != nil {
		return nil, err
	}

	return root.GetNode()
}
926706
func (c *cache) finalizer() {
	if c.mmap != nil {
		c.mmap.Unmap()
		c.dump.Close()
		c.mmap, c.dump = nil, nil
	}
}
337293
func (cr *ConflictResolver) finalizeResolution(ctx context.Context,
	lState *kbfssync.LockState, md *RootMetadata,
	unmergedChains, mergedChains *crChains,
	updates map[data.BlockPointer]data.BlockPointer,
	bps blockPutState, blocksToDelete []kbfsblock.ID, writerLocked bool) error {
	err := cr.checkDone(ctx)
	if err != nil {
		return err
	}

	// Fix up all the block pointers in the merged ops to work well
	// for local notifications.  Make a dummy op at the beginning to
	// convert all the merged most recent pointers into unmerged most
	// recent pointers.
	newOps, err := cr.getOpsForLocalNotification(
		ctx, lState, md, unmergedChains,
		mergedChains, updates)
	if err != nil {
		return err
	}

	cr.log.CDebugf(ctx, "Local notifications: %v", newOps)

	if writerLocked {
		return cr.fbo.finalizeResolutionLocked(
			ctx, lState, md, bps, newOps, blocksToDelete)
	}
	return cr.fbo.finalizeResolution(
		ctx, lState, md, bps, newOps, blocksToDelete)
}
113081
func (rs *retributionStore) Finalize(chanPoint *wire.OutPoint,
	finalTx *wire.MsgTx) error {
	return rs.db.Update(func(tx *bbolt.Tx) error {
		justiceBkt, err := tx.CreateBucketIfNotExists(justiceTxnBucket)
		if err != nil {
			return err
		}

		var chanBuf bytes.Buffer
		if err := writeOutpoint(&chanBuf, chanPoint); err != nil {
			return err
		}

		var txBuf bytes.Buffer
		if err := finalTx.Serialize(&txBuf); err != nil {
			return err
		}

		return justiceBkt.Put(chanBuf.Bytes(), txBuf.Bytes())
	})
}
1044455
func (c *RefCount) Finalizer() resource.Finalizer {
	finalizerPtr := (*resource.Finalizer)(atomic.LoadPointer(&c.finalizer))
	if finalizerPtr == nil {
		return nil
	}
	return *finalizerPtr
}
983547
func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
	return false, fmt.Errorf("Resize is not supported for this build")
}
1015388
func (e *GT) Finalize() *GT {
	ret := finalExponentiation(e.p)
	e.p.Set(ret)
	return e
}
1374892
func (s *StateDB) Finalise(deleteEmptyObjects bool) {
	for addr := range s.journal.dirties {
		stateObject, exist := s.stateObjects[addr]
		if !exist {
			// ripeMD is 'touched' at block 1714175, in tx 0x1237f737031e40bcde4a8b7e717b2d15e3ecadfe49bb1bbc71ee9deb09c6fcf2
			// That tx goes out of gas, and although the notion of 'touched' does not exist there, the
			// touch-event will still be recorded in the journal. Since ripeMD is a special snowflake,
			// it will persist in the journal even though the journal is reverted. In this special circumstance,
			// it may exist in `s.journal.dirties` but not in `s.stateObjects`.
			// Thus, we can safely ignore it here
			continue
		}

		if stateObject.suicided || (deleteEmptyObjects && stateObject.empty()) {
			s.deleteStateObject(stateObject)
		} else {
			stateObject.updateRoot(s.db)
			s.updateStateObject(stateObject)
		}
		s.stateObjectsDirty[addr] = struct{}{}
	}
	// Invalidate journal because reverting across transactions is not allowed.
	s.clearJournalAndRefund()
}
755927
func rootify(path, root string) string {
	if filepath.IsAbs(path) {
		return path
	}
	return filepath.Join(root, path)
}
1012334
func Finalize(err *error, tx *sql.Tx) {
	if *err == nil {
		*err = tx.Commit()
		if *err != nil {
			fmt.Fprintf(os.Stderr, "[!] failed to commit transaction: %s\n", *err)
			os.Exit(1)
		}
	} else {
		tx.Rollback()
	}
}
914921
func (b *Builder) Finish() error {
	b.flush()
	b.building.Wait()

	if b.buildError != nil {
		for tmp := range b.finishedShards {
			os.Remove(tmp)
		}
		return b.buildError
	}

	for tmp, final := range b.finishedShards {
		if err := os.Rename(tmp, final); err != nil {
			b.buildError = err
		}
	}

	if b.nextShardNum > 0 {
		b.deleteRemainingShards()
	}
	return b.buildError
}
445502
func (s *Service) FinalizeGsUpload(handlersendpointsv1finalizerequest *HandlersEndpointsV1FinalizeRequest) *FinalizeGsUploadCall {
	c := &FinalizeGsUploadCall{s: s, urlParams_: make(gensupport.URLParams)}
	c.handlersendpointsv1finalizerequest = handlersendpointsv1finalizerequest
	return c
}
721110
func (m *Metrics) Finalize(rateLimit uint, totalQueries uint) {
	if rateLimit == 0 {
		rateLimit = 1
	}

	for _, s := range m.TimeMetrics {
		sort.Float64s(s.vals)
		cnt := len(s.vals)

		s.Min = Float64(s.vals[0])
		s.Med = Float64(s.vals[(50*cnt)/100]) // median = 50th percentile
		s.P95 = Float64(s.vals[(95*cnt)/100])
		s.Max = Float64(s.vals[cnt-1])
		s.Sum = (s.Sum * float64(rateLimit)) + s.outlierSum
		s.Avg = Float64(s.Sum / float64(totalQueries))
	}

	for _, s := range m.NumberMetrics {
		sort.Sort(byUint64(s.vals))
		cnt := len(s.vals)

		s.Min = Uint64(s.vals[0])
		s.Med = Uint64(s.vals[(50*cnt)/100]) // median = 50th percentile
		s.P95 = Uint64(s.vals[(95*cnt)/100])
		s.Max = Uint64(s.vals[cnt-1])
		s.Sum = (s.Sum * uint64(rateLimit)) + s.outlierSum
		s.Avg = Uint64(s.Sum / uint64(totalQueries))
	}

	for _, s := range m.BoolMetrics {
		s.Sum = (s.Sum * uint64(rateLimit)) + s.outlierSum
	}
}
888608
func (e *Editor) Finalize(ctx context.Context, ds ipld.DAGService) (*dag.ProtoNode, error) {
	nd := e.GetNode()
	err := copyDag(ctx, nd, e.tmp, ds)
	return nd, err
}
1057231
func (s *SecuritySchemeDefinition) Finalize() {
	tu, _ := url.Parse(s.TokenURL)         // validated in Validate
	au, _ := url.Parse(s.AuthorizationURL) // validated in Validate
	tokenOK := s.TokenURL == "" || tu.IsAbs()
	authOK := s.AuthorizationURL == "" || au.IsAbs()
	if tokenOK && authOK {
		return
	}
	var scheme string
	if len(Design.Schemes) > 0 {
		scheme = Design.Schemes[0]
	}
	if !tokenOK {
		tu.Scheme = scheme
		tu.Host = Design.Host
		s.TokenURL = tu.String()
	}
	if !authOK {
		au.Scheme = scheme
		au.Host = Design.Host
		s.AuthorizationURL = au.String()
	}
}
1052114
func (k *KeybaseServiceBase) FinalizeMigration(ctx context.Context,
	folder keybase1.Folder) (err error) {
	fav := favorites.NewFolderFromProtocol(folder)
	handle, err := GetHandleFromFolderNameAndType(
		ctx, k.config.KBPKI(), k.config.MDOps(), k.config, fav.Name, fav.Type)
	if err != nil {
		return err
	}
	if handle.TypeForKeying() == tlf.TeamKeying {
		// Clear the cache for this implicit team, to ensure we get
		// all the latest key generations for the team info during the
		// migration.
		id := handle.FirstResolvedWriter()
		if id.IsTeamOrSubteam() {
			tid, err := id.AsTeam()
			if err != nil {
				return err
			}
			k.log.CDebugf(ctx, "Clearing team info for tid=%s, handle=%s",
				tid, handle.GetCanonicalPath())
			k.setCachedTeamInfo(tid, idutil.TeamInfo{})
		}
	}
	return k.config.KBFSOps().MigrateToImplicitTeam(ctx, handle.TlfID())
}
596350
func (megaPi *Adaptor) Finalize() error {
	megaPi.finalizeChannel <- struct{}{}
	<-megaPi.finalizeChannel
	if err := megaPi.connection.Close(); err != nil {
		return err
	}
	return nil
}