// Clean checks all session files on disk to see if they are older than
// maxAge by checking their access time. If it finds an expired session file
// it will remove it from disk.
764294
func (d *DiskStorer) Clean() {
	t := time.Now().UTC()

	files, err := ioutil.ReadDir(d.folderPath)

	if err != nil {
		panic(err)
	}

	for _, file := range files {
		tspec := times.Get(file)

		// File is expired
		if tspec.AccessTime().UTC().UTC().Add(d.maxAge).Before(t) {
			filePath := path.Join(d.folderPath, file.Name())

			d.mut.Lock()
			_, err := os.Stat(filePath)
			// If the file has been deleted manually from the server
			// in between the time we read the directory and now, it will
			// fail here with a ErrNotExist. If so, continue gracefully.
			// It would be innefficient to hold a lock for the duration of
			// the loop, so we only lock when we find an expired file.
			if os.IsNotExist(err) {
				d.mut.Unlock()
				continue
			} else if err != nil {
				panic(err)
			}

			err = os.Remove(filePath)
			d.mut.Unlock()
			if err != nil {
				panic(err)
			}
		}
	}
}
1116929
func (s *LoginSession) Clear() error {
	if s == nil {
		return nil
	}
	if !s.loaded {
		return ErrLoginSessionNotLoaded
	}
	s.loginSession = nil
	s.loginSessionB64 = ""
	s.cleared = true
	return nil
}
1348792
func (ctx *AssertContext) Cleanup() {
	os.Remove(ctx.ConfigPath)
	os.Remove(ctx.ContentFile)

	if ctx.serviceAccountPath != "" {
		os.Remove(ctx.serviceAccountPath)
	}
	os.Unsetenv(GoogleAppCredentialsEnv)
}
693181
func (exporter *logExporter) cleanup() {
	// Close all of the temporary files
	for _, outputFile := range exporter.outputFiles {
		if e := outputFile.File.Close(); e != nil {
			log.WithFields(logrus.Fields{
				"outputfile": outputFile.Name,
			}).WithError(e).Error("Failed to close file cleanly")
		}
	}

	if exporter.parseWarningsFile != nil {
		if e := exporter.parseWarningsFile.Close(); e != nil {
			log.WithFields(logrus.Fields{
				"warningsfile": exporter.parseWarningsFilename,
			}).WithError(e).Error("Failed to close file cleanly")
		}
	}

	// close the tar file
	if exporter.outFile != nil {
		exporter.outFile.Close()
	}

	if exporter.tempdir != "" {
		os.RemoveAll(exporter.tempdir)
	}
}
832285
func (p *Project) Clean(keep bool) error {
	containers, err := p.List()
	if err != nil {
		return err
	}
	for _, container := range containers {
		if err := p.StopWithTimeout(container.ID, 1); err != nil {
			return err
		}
		if !keep {
			if err := p.Remove(container.ID); err != nil {
				return err
			}
		}
	}
	return nil
}
1358377
func (m *mapReact) Clean() {
	m.ro.Lock()
	m.ma = make(map[SenderDetachCloser]bool)
	m.ro.Unlock()
}
97392
func (d *Driver) Cleanup() error {
	items, err := ioutil.ReadDir(d.info.HomeDir)
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}

	// Note we don't return an error below - it's possible the files
	// are locked. However, next time around after the daemon exits,
	// we likely will be able to cleanup successfully. Instead we log
	// warnings if there are errors.
	for _, item := range items {
		if item.IsDir() && strings.HasSuffix(item.Name(), "-removing") {
			if err := hcsshim.DestroyLayer(d.info, item.Name()); err != nil {
				logrus.Warnf("Failed to cleanup %s: %s", item.Name(), err)
			} else {
				logrus.Infof("Cleaned up %s", item.Name())
			}
		}
	}

	return nil
}
529482
func (d *Dir) Cleanup(ctx context.Context, fi *dokan.FileInfo) {
	var err error
	if fi != nil {
		d.folder.fs.logEnterf(ctx, "Dir Cleanup %q delete=%v", d.name,
			fi.IsDeleteOnClose())
	} else {
		d.folder.fs.logEnterf(ctx, "Dir Cleanup %q", d.name)
	}
	defer func() { d.folder.reportErr(ctx, libkbfs.WriteMode, err) }()

	if fi != nil && fi.IsDeleteOnClose() && d.parent != nil {
		// renameAndDeletionLock should be the first lock to be grabbed in libdokan.
		d.folder.fs.renameAndDeletionLock.Lock()
		defer d.folder.fs.renameAndDeletionLock.Unlock()
		d.folder.fs.vlog.CLogf(
			ctx, libkb.VLog1, "Removing (Delete) dir in cleanup %s", d.name)

		err = d.folder.fs.config.KBFSOps().RemoveDir(ctx, d.parent, d.name)
	}

	if d.refcount.Decrease() {
		d.folder.forgetNode(ctx, d.node)
	}
}
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)
}
749568
func Cleanse(v interface{}) interface{} {
	if v == nil {
		return nil
	}

	va, vIsArr := v.([]interface{})
	if vIsArr {
		var a []interface{}
		if va != nil {
			a = []interface{}{}
		}
		for _, vav := range va {
			a = append(a, Cleanse(vav))
		}
		return a
	}

	vm, vIsMap := v.(map[string]interface{})
	if vIsMap && vm != nil {
		m := map[string]interface{}{}
		for vmk, vmv := range vm {
			if vmk == "display_order" {
				continue
			}
			m[vmk] = Cleanse(vmv)
		}
		return m
	}

	return v
}
652258
func (c *Config) CleanUp() {
	for _, d := range c.Definitions.All {
		sort.Sort(d.AppearsIn)
		sort.Sort(d.Fields)
		dedup := SortDefinitionsByName{}
		var last *Definition
		for _, i := range d.AppearsIn {
			if last != nil &&
				i.Name == last.Name &&
				i.Group.String() == last.Group.String() &&
				i.Version.String() == last.Version.String() {
				continue
			}
			last = i
			dedup = append(dedup, i)
		}
		d.AppearsIn = dedup
	}
}
904131
func (out DirOutput) Clean() error {
	return errorsp.WithStacks(sophie.FsPath(out).Remove())
}
32021
func (c *UserServiceController) Clean(ctx *app.CleanUserServiceContext) error {
	err := c.CleanTenant(ctx, ctx.Remove)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	return ctx.OK([]byte{})
}
928520
func (ctl *HandshakeController) clean() {
	peerpubkeys := ctl.handshakes
	for pubkeyid, peertopics := range peerpubkeys {
		for topic := range peertopics {
			ctl.cleanHandshake(pubkeyid, &topic, true, true)
		}
	}
}
774644
func clearSession(sid string, isForce bool) {
	var toRemove []string
	if sid == "all" {
		toRemove = getSessionIDs()
	} else {
		toRemove = append(toRemove, sid)
	}
	for _, sid := range toRemove {
		session, err := loadSessionV8(sid)
		if !isForce {
			fatalIf(err.Trace(sid), "Unable to load session `"+sid+"`. Use --force flag to remove obsolete session files.")

			fatalIf(session.Delete().Trace(sid), "Unable to remove session `"+sid+"`. Use --force flag to remove obsolete session files.")

			printMsg(clearSessionMessage{Status: "success", SessionID: sid})
			continue
		}
		// Forced removal of a session.
		forceClear(sid, session)
	}
	return
}
1048659
func (s *Session) Clear() {
	s.mu.Lock()
	s.provider.db.Clear(s.sid)
	s.isNew = false
	s.mu.Unlock()
}
566665
func cleanup(files ...*os.File) {
	for _, file := range files {
		_ = file.Close()
		_ = os.Remove(file.Name())
	}
}