// CleanBom returns b with the 3 byte BOM stripped off the front if it is present.
// If the BOM is not present, then b is returned.
167709
func CleanBom(b []byte) []byte {
	if len(b) >= 3 &&
		b[0] == bom0 &&
		b[1] == bom1 &&
		b[2] == bom2 {
		return b[3:]
	}
	return b
}
152340
func (d *DB) deleteObsoleteFiles() {
	liveFileNums := map[uint64]struct{}{}
	for fileNum := range d.pendingOutputs {
		liveFileNums[fileNum] = struct{}{}
	}
	d.versions.addLiveFileNums(liveFileNums)
	logNumber := d.versions.logNumber
	manifestFileNumber := d.versions.manifestFileNumber

	// Release the d.mu lock while doing I/O.
	// Note the unusual order: Unlock and then Lock.
	d.mu.Unlock()
	defer d.mu.Lock()

	fs := d.opts.GetFileSystem()
	list, err := fs.List(d.dirname)
	if err != nil {
		// Ignore any filesystem errors.
		return
	}
	for _, filename := range list {
		fileType, fileNum, ok := parseDBFilename(filename)
		if !ok {
			return
		}
		keep := true
		switch fileType {
		case fileTypeLog:
			// TODO: also look at prevLogNumber?
			keep = fileNum >= logNumber
		case fileTypeManifest:
			keep = fileNum >= manifestFileNumber
		case fileTypeTable, fileTypeOldFashionedTable:
			_, keep = liveFileNums[fileNum]
		}
		if keep {
			continue
		}
		if fileType == fileTypeTable {
			d.tableCache.evict(fileNum)
		}
		// Ignore any file system errors.
		fs.Remove(filepath.Join(d.dirname, filename))
	}
}
1180714
func Clean(os, path string) string {
	abs := IsAbs(os, path)
	sep := Separator(os)
	elements := strings.Split(path, string(sep))

	// Replace multiple Separator elements with a single one.
	for i := 0; i < len(elements); i++ {
		if len(elements[i]) == 0 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}

	// Eliminate each . path name element (the current directory).
	for i := 0; i < len(elements); i++ {
		if elements[i] == "." && len(elements) > 1 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}

	// Eliminate each inner .. path name element (the parent directory)
	// along with the non-.. element that precedes it.
	for i := 1; i < len(elements); i++ {
		if i == 1 && abs && sep == '\\' {
			continue
		}
		if i > 0 && elements[i] == ".." {
			elements = append(elements[:i-1], elements[i+1:]...)
			i -= 2
		}
	}

	// Eliminate .. elements that begin a rooted path:
	// that is, replace "/.." by "/" at the beginning of a path,
	// assuming Separator is '/'.
	offset := 0
	if sep == '\\' {
		offset = 1
	}
	if abs {
		for len(elements) > offset && elements[offset] == ".." {
			elements = append(elements[:offset], elements[offset+1:]...)
		}
	}

	cleaned := strings.Join(elements, string(sep))
	if abs {
		if sep == '/' {
			cleaned = fmt.Sprintf("%c%s", sep, cleaned)
		} else if len(elements) == 1 {
			cleaned = fmt.Sprintf("%s%c", cleaned, sep)
		}
	}

	// If the result of this process is an empty string, Clean returns
	// the string ".".
	if len(cleaned) == 0 {
		cleaned = "."
	}

	if cleaned == path {
		return path
	}
	return Clean(os, cleaned)
}
1019712
func (bfp *BootFileParam) UnmarshalBinary(b []byte) error {
	var d Data
	if err := (&d).UnmarshalBinary(b); err != nil {
		return err
	}
	// Convert [][]byte to []string.
	*bfp = make([]string, 0, len(d))
	for _, param := range d {
		*bfp = append(*bfp, string(param))
	}
	return nil
}
134655
func (st *State) cleanupUnitsForDyingApplication(applicationname string, cleanupArgs []bson.Raw) (err error) {
	var destroyStorage bool
	destroyStorageArg := func() error {
		err := cleanupArgs[0].Unmarshal(&destroyStorage)
		return errors.Annotate(err, "unmarshalling cleanup arg 'destroyStorage'")
	}
	var force bool
	var maxWait time.Duration
	switch n := len(cleanupArgs); n {
	case 0:
	// It's valid to have no args: old cleanups have no args, so follow the old behaviour.
	case 1:
		if err := destroyStorageArg(); err != nil {
			return err
		}
	case 3:
		if err := destroyStorageArg(); err != nil {
			return err
		}
		if err := cleanupArgs[1].Unmarshal(&force); err != nil {
			return errors.Annotate(err, "unmarshalling cleanup arg 'force'")
		}
		if err := cleanupArgs[2].Unmarshal(&maxWait); err != nil {
			return errors.Annotate(err, "unmarshalling cleanup arg 'maxWait'")
		}
	default:
		return errors.Errorf("expected 0, 1 or 3 arguments, got %d", n)
	}

	// This won't miss units, because a Dying application cannot have units
	// added to it. But we do have to remove the units themselves via
	// individual transactions, because they could be in any state at all.
	units, closer := st.db().GetCollection(unitsC)
	defer closer()

	unit := Unit{st: st}
	sel := bson.D{{"application", applicationname}, {"life", Alive}}
	iter := units.Find(sel).Iter()
	defer closeIter(iter, &err, "reading unit document")
	for iter.Next(&unit.doc) {
		op := unit.DestroyOperation()
		op.DestroyStorage = destroyStorage
		op.Force = force
		op.MaxWait = maxWait
		if err := st.ApplyOperation(op); err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
306529
func filterAbs(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
	n := stick.CoerceNumber(val)
	if 0 == n {
		return n
	}
	return math.Abs(n)
}
88529
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {

	// Bail out now for Linux containers
	if system.LCOWSupported() && container.OS != "windows" {
		return nil
	}

	// We do not unmount if a Hyper-V container
	if !daemon.runAsHyperVContainer(container.HostConfig) {
		return daemon.Unmount(container)
	}
	return nil
}
992778
func (r *RetryInfo) Clean() {
	r.currRetryOff = 0
	if len(r.autoIncrementIDs) > 0 {
		r.autoIncrementIDs = r.autoIncrementIDs[:0]
	}
	if len(r.DroppedPreparedStmtIDs) > 0 {
		r.DroppedPreparedStmtIDs = r.DroppedPreparedStmtIDs[:0]
	}
}
369370
func (c *Config) GetBool(key string) (b bool) {
	b, _ = c.GetBoolOk(key)
	return
}
466440
func (p *Project) Clean(c *check.C, keep bool) {
	c.Assert(p.project.Clean(keep), check.IsNil,
		check.Commentf("error while cleaning the containers"))
}
750452
func (ioctx *IOContext) CleanOmap(oid string) error {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	op := C.rados_create_write_op()
	C.rados_write_op_omap_clear(op)

	ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
	C.rados_release_write_op(op)

	return GetRadosError(int(ret))
}
610182
func RollbackCleanupOnFail(cleanupOnFail bool) RollbackOption {
	return func(opts *options) {
		opts.rollbackReq.CleanupOnFail = cleanupOnFail
	}
}
379435
func (e *Element) CleanRemoved() {
	for n, em := range e.children {
		if em.Removed() {
			copy(e.children[n:], e.children[n+1:])
			e.children = e.children[:len(e.children)-1]
		} else {
			em.CleanRemoved()
		}
	}
}
495026
func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error {
	return daemon.Unmount(container)
}
752300
func (w *Worktree) Clean(opts *CleanOptions) error {
	s, err := w.Status()
	if err != nil {
		return err
	}

	root := ""
	files, err := w.Filesystem.ReadDir(root)
	if err != nil {
		return err
	}
	return w.doClean(s, opts, root, files)
}
408042
func cleanFilename(path string) string {
	const prefix = "$GOROOT"
	if len(path) < len(prefix) || !strings.EqualFold(prefix, path[:len(prefix)]) {
		return path
	}
	//TODO: we need a better way to get the GOROOT that uses the packages api
	return runtime.GOROOT() + path[len(prefix):]
}
519409
func (c *Client) RemoveBlob(ctx context.Context, b blob.Ref) error {
	return c.RemoveBlobs(ctx, []blob.Ref{b})
}