示例#1
0
文件: index.go 项目: koding/koding
// ctime gets file's change time in UNIX Nano format.
func ctime(fi os.FileInfo) int64 {
	if tspec := times.Get(fi); tspec.HasChangeTime() {
		return tspec.ChangeTime().UnixNano()
	}

	return 0
}
示例#2
0
// Clean (remove) files in `md+"/tmp/"` not accessed in the last 36
// hours.
func (md Maildir) Clean() error {
	dir, err := os.Open(string(md) + "/tmp")
	if err != nil {
		return err
	}
	fileinfos, err := dir.Readdir(0)
	if err != nil {
		return err
	}
	for _, fileinfo := range fileinfos {
		if strings.HasPrefix(fileinfo.Name(), ".") {
			continue
		}
		atime := times.Get(fileinfo).AccessTime()
		if time.Since(atime) > (36 * time.Hour) {
			path := string(md) + "/tmp/" + fileinfo.Name()
			err1 := syscall.Unlink(path)
			if err1 != nil {
				err = &os.PathError{Op: "unlink", Path: path, Err: err1}
			}
		}
	}
	return err
}