当前位置: 首页>>代码示例>>Golang>>正文


Golang FileInfo.ModTime方法代码示例

本文整理汇总了Golang中os.FileInfo.ModTime方法的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo.ModTime方法的具体用法?Golang FileInfo.ModTime怎么用?Golang FileInfo.ModTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.FileInfo的用法示例。


在下文中一共展示了FileInfo.ModTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetHash

// Return the hash for path stored in the xattrs. If the hash is out of date,
// the hash is computed anew, unless `compute` is false in which case nil is
// returned.
func GetHash(path string, info os.FileInfo, compute bool) (mh.Multihash, error) {
	if info.Mode()&os.ModeSymlink != 0 {
		return symlinkHash(path)
	}

	hashTimeStr, err := attrs.Get(path, XattrHashTime)
	if err != nil {
		if compute {
			return HashFile(path, info)
		} else if IsNoData(err) {
			// ignore error
			return nil, nil
		} else {
			return nil, err
		}
	}

	hashTime, err := time.Parse(time.RFC3339Nano, string(hashTimeStr))
	if err != nil {
		return nil, err
	}

	if hashTime != info.ModTime() {
		if compute {
			return HashFile(path, info)
		} else {
			return nil, nil
		}
	}

	return attrs.Get(path, XattrHash)
}
开发者ID:mildred,项目名称:doc,代码行数:35,代码来源:hash.go

示例2: Finfo2Theader

// create tar.Header from os.FileInfo
func Finfo2Theader(fi os.FileInfo) (hdr *tar.Header, err error) {
	m := fi.Mode()
	var (
		ln string
		tm byte
	)
	tm = tar.TypeReg
	switch {
	case m&os.ModeSymlink != 0:
		tm = tar.TypeSymlink
		/*if lfi, err := os.Lstat(fi.Name()); err == nil {
			ln = lfi.Name()
		}*/
	case m&os.ModeDevice != 0 && m&os.ModeCharDevice != 0:
		tm = tar.TypeChar
	case m&os.ModeDevice != 0:
		tm = tar.TypeBlock
	case m&os.ModeNamedPipe != 0 || m&os.ModeSocket != 0:
		tm = tar.TypeFifo
	}
	tim := fi.ModTime()
	hdr = &tar.Header{Name: fi.Name(), Mode: int64(m.Perm()),
		Size: fi.Size(), ModTime: tim,
		Typeflag: tm, Linkname: ln}
	FillHeader(hdr)
	return
}
开发者ID:tgulacsi,项目名称:aostor,代码行数:28,代码来源:tarhelper.go

示例3: archiveFile

func archiveFile(fname string, cfg *conf.Config, rootStat os.FileInfo, fs os.FileInfo) (newname string, err error) {
	year := strconv.Itoa(fs.ModTime().Year())
	month := fs.ModTime().Month().String()

	archivePath := filepath.Join(cfg.ArchivePath(rootStat.Name()), year, month)
	err = os.MkdirAll(archivePath, rootStat.Mode())
	if err != nil && !os.IsExist(err) {
		return
	}

	zipPath := archivePath + ".zip"
	if util.FileExists(zipPath) {
		//unzip so we can archive the new file ... it will be rezipped later
		if err = util.Unzip(zipPath, archivePath); err != nil {
			return
		}
	}

	newname = filepath.Join(archivePath, fs.Name())
	if _, err = os.Stat(newname); err == nil {
		err = fmt.Errorf("A file of the same name already exists in the archive")
		return
	}
	err = os.Rename(fname, newname)

	return
}
开发者ID:jquag,项目名称:kempt,代码行数:27,代码来源:archive.go

示例4: shouldUpdate

func shouldUpdate(resp *http.Response, fi os.FileInfo, newer, newermetamtime bool) bool {
	var stale bool = false
	filemtime := fi.ModTime()
	if newermetamtime {
		parsed, err := time.Parse(time.RFC1123, resp.Header.Get("x-amz-meta-last-modified"))
		if err != nil {
			// can't see metamtime upload anyhow
			stale = true
			fmt.Fprint(os.Stderr, "Can't read metamtime, setting stale to upload again\n")
		}
		if parsed.Before(filemtime) {
			stale = true
		}
	}
	if newer {
		parsed, err := time.Parse(time.RFC1123, resp.Header.Get("Last-Modified"))
		if err != nil {
			// can't see metamtime upload anyhow
			stale = true
			fmt.Fprint(os.Stderr, "Can't read metamtime, setting stale to upload again\n")
		}
		if parsed.Before(filemtime) {
			stale = true
		}
	}
	return stale
}
开发者ID:reedobrien,项目名称:wpgo,代码行数:27,代码来源:fs2s3.go

示例5: checkHtmlDoWrite

func (p *Page) checkHtmlDoWrite(tplFi, htmlFi os.FileInfo, htmlErr error) bool {
	var doWrite bool
	if p.Config.AutoGenerateHtmlCycleTime <= 0 {
		doWrite = true
	} else {
		if htmlErr != nil {
			doWrite = true
		} else {
			switch {
			case tplFi.ModTime().Unix() >= htmlFi.ModTime().Unix():
				doWrite = true
			case tplFi.ModTime().Unix() >= htmlFi.ModTime().Unix():
				doWrite = true
			case time.Now().Unix()-htmlFi.ModTime().Unix() >= p.Config.AutoGenerateHtmlCycleTime:
				doWrite = true
			default:
				if globalTplCache := p.site.GetTemplateCache("globalTpl"); globalTplCache.ModTime > 0 && globalTplCache.ModTime >= htmlFi.ModTime().Unix() {
					doWrite = true
				}
			}
		}
	}

	return doWrite
}
开发者ID:JessonChan,项目名称:framework,代码行数:25,代码来源:page.go

示例6: visit

func (self *F) visit(path string, f os.FileInfo, err error) error {
	if f == nil {
		return err
	}
	//如果是txt文本
	if strings.HasSuffix(f.Name(), "txt") {
		var tp int
		if f.IsDir() {
			tp = IsDirectory
		} else if (f.Mode() & os.ModeSymlink) > 0 {
			tp = IsSymlink
		} else {
			tp = IsRegular
		}
		inoFile := &sysFile{
			fName:      path,
			fType:      tp,
			fPerm:      f.Mode(),
			fMtime:     f.ModTime(),
			fSize:      f.Size(),
			fShortName: f.Name(),
		}
		self.files = append(self.files, inoFile)
	}
	return nil
}
开发者ID:sogyf,项目名称:Story-Figures,代码行数:26,代码来源:mdi.go

示例7: TarGzWrite

// Write a single file to TarGz
func TarGzWrite(item ArchiveItem, tw *tar.Writer, fi os.FileInfo) (err error) {
	if item.FileSystemPath != "" {
		fr, err := os.Open(item.FileSystemPath)
		if err == nil {
			defer fr.Close()

			h := new(tar.Header)
			h.Name = item.ArchivePath
			h.Size = fi.Size()
			h.Mode = int64(fi.Mode())
			h.ModTime = fi.ModTime()

			err = tw.WriteHeader(h)

			if err == nil {
				_, err = io.Copy(tw, fr)
			}
		}
	} else {
		h := new(tar.Header)
		//backslash-only paths
		h.Name = strings.Replace(item.ArchivePath, "\\", "/", -1)
		h.Size = int64(len(item.Data))
		h.Mode = int64(0644) //? is this ok?
		h.ModTime = time.Now()
		err = tw.WriteHeader(h)
		if err == nil {
			_, err = tw.Write(item.Data)
		}
	}
	return err
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:33,代码来源:targz.go

示例8: procesImage

func procesImage(path string, f os.FileInfo, err error) error {
	if f.IsDir() {
		return nil
	}

	log.Debugf("Processing %s", path)

	extension := filepath.Ext(f.Name())
	if !isSupportPhotoType(strings.ToLower(extension)) {
		log.Warnf("%s's file type %s is unsupported", path, extension)
		return nil
	}

	reader := exif.New()

	err = reader.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	str := fmt.Sprintf("%s", reader.Tags["Date and Time"])
	t := f.ModTime()

	if len(str) == 0 {
		log.Warnf("Date and Time EXIF tag missing for %s", path)
	} else {
		layout := "2006:01:02 15:04:05"
		t, err = time.Parse(layout, str)
		if err != nil {
			log.Fatal(err)
		}
	}

	newDir := fmt.Sprintf("%s/%4d/%02d/%02d", destPath, t.Year(), t.Month(), t.Day())

	err = os.MkdirAll(newDir, 0777)
	if err != nil {
		log.Fatal(err)
	}

	newFile := fmt.Sprintf("%s/%s", newDir, f.Name())

	if mode == "move" {
		log.Debugf("Moving %s %s", path, newFile)
		err = os.Rename(path, newFile)
	} else {
		if _, err := os.Stat(newFile); err == nil {
			log.Warnf("Photo %s already exists", newFile)
		} else {
			log.Debugf("Copying %s %s", path, newFile)
			err = copyFile(path, newFile)
		}
	}

	if err != nil {
		log.Fatal(err)
	}

	return nil
}
开发者ID:ashmckenzie,项目名称:photoman,代码行数:60,代码来源:main.go

示例9: fillLocalfsImage

func (repo *LocalfsImagerep) fillLocalfsImage(image *models.Image, fileinfo os.FileInfo) bool {

	// ubuntu-14.04_x86_64_raw.img -> name: ubuntu-14.04, arch: x86_64, type: raw.img
	imginfo := strings.SplitN(fileinfo.Name(), "_", 3)

	if len(imginfo) != 3 {
		log.WithField("image", fileinfo.Name()).Info("skipping image with invalid name")
		return false
	}

	image.Name = imginfo[0]
	image.Size = fileinfo.Size()
	image.Date = fileinfo.ModTime()
	image.Filename = fileinfo.Name()
	image.FullPath = filepath.Join(repo.Root, fileinfo.Name())
	switch imginfo[1] {
	default:
		log.WithField("filename", fileinfo.Name()).WithField("parts", imginfo).Info("skipping unknown image architecture")
		return false
	case "amd64":
		image.Arch = models.IMAGE_ARCH_X86_64
	case "i386":
		image.Arch = models.IMAGE_ARCH_X86
	}
	switch imginfo[2] {
	default:
		log.WithField("filename", fileinfo.Name()).WithField("parts", imginfo).Info("skipping unknown image type")
		return false
	case "raw.img":
		image.Type = models.IMAGE_FMT_RAW
	case "qcow2.img":
		image.Type = models.IMAGE_FMT_QCOW2
	}
	return true
}
开发者ID:subuk,项目名称:vmango,代码行数:35,代码来源:imagerep_localfs.go

示例10: watch

// watch watchers the file for changes
func (d *FileQuery) watch(lastStat os.FileInfo) <-chan *watchResult {
	ch := make(chan *watchResult, 1)

	go func(lastStat os.FileInfo) {
		for {
			stat, err := os.Stat(d.path)
			if err != nil {
				select {
				case <-d.stopCh:
					return
				case ch <- &watchResult{err: err}:
					return
				}
			}

			changed := lastStat == nil ||
				lastStat.Size() != stat.Size() ||
				lastStat.ModTime() != stat.ModTime()

			if changed {
				select {
				case <-d.stopCh:
					return
				case ch <- &watchResult{stat: stat}:
					return
				}
			}

			time.Sleep(FileQuerySleepTime)
		}
	}(lastStat)

	return ch
}
开发者ID:hashicorp,项目名称:consul-replicate,代码行数:35,代码来源:file.go

示例11: GetLatestReport

// GetLatestReport searches the storageLocation to find the latest report file.
// It searches based on filename, not on modified or created time, because
// both can be updated after/before the date in the filename.
func (fs *FilesystemBackend) GetLatestReport() (File, error) {
	var reporterFile File
	files, err := ioutil.ReadDir(fs.storageLocation)
	if err != nil {
		return reporterFile, err
	}
	var latestDate time.Time
	var latestFile os.FileInfo
	for _, file := range files {
		if strings.Contains(file.Name(), "-reporter-export.json") {
			filenameDate, err := dateForFilename(file.Name())
			if err != nil {
				return reporterFile, err
			}
			if filenameDate.After(latestDate) {
				latestDate = filenameDate
				latestFile = file
			}
		}
	}
	filePath := filepath.Join(fs.storageLocation, latestFile.Name())
	fileContents, err := ioutil.ReadFile(filePath)
	if err != nil {
		return reporterFile, err
	}
	return File{
		Name:             latestFile.Name(),
		Path:             filePath,
		Source:           "filesystem",
		ModifiedTime:     latestFile.ModTime(),
		TimeFromFilename: latestDate,
		Contents:         string(fileContents),
	}, nil
}
开发者ID:robbiet480,项目名称:go.reporter,代码行数:37,代码来源:filesystem.go

示例12: listVols

// List all the volumes from diskPath.
func listVols(dirPath string) ([]VolInfo, error) {
	if err := checkPathLength(dirPath); err != nil {
		return nil, err
	}
	entries, err := readDir(dirPath)
	if err != nil {
		return nil, errDiskNotFound
	}
	var volsInfo []VolInfo
	for _, entry := range entries {
		if !strings.HasSuffix(entry, slashSeparator) || !isValidVolname(slashpath.Clean(entry)) {
			// Skip if entry is neither a directory not a valid volume name.
			continue
		}
		var fi os.FileInfo
		fi, err = os.Stat(preparePath(pathJoin(dirPath, entry)))
		if err != nil {
			// If the file does not exist, skip the entry.
			if os.IsNotExist(err) {
				continue
			}
			return nil, err
		}
		volsInfo = append(volsInfo, VolInfo{
			Name: fi.Name(),
			// As os.Stat() doesn't carry other than ModTime(), use
			// ModTime() as CreatedTime.
			Created: fi.ModTime(),
		})
	}
	return volsInfo, nil
}
开发者ID:balamurugana,项目名称:minio,代码行数:33,代码来源:posix.go

示例13: isNewer

func (node *Node) isNewer(path string, fi os.FileInfo) bool {
	if node.Type != "file" {
		debug.Log("node.isNewer", "node %v is newer: not file", path)
		return true
	}

	tpe := nodeTypeFromFileInfo(fi)
	if node.Name != fi.Name() || node.Type != tpe {
		debug.Log("node.isNewer", "node %v is newer: name or type changed", path)
		return true
	}

	extendedStat := fi.Sys().(*syscall.Stat_t)
	inode := extendedStat.Ino
	size := uint64(extendedStat.Size)

	if node.ModTime != fi.ModTime() ||
		node.ChangeTime != changeTime(extendedStat) ||
		node.Inode != uint64(inode) ||
		node.Size != size {
		debug.Log("node.isNewer", "node %v is newer: timestamp, size or inode changed", path)
		return true
	}

	debug.Log("node.isNewer", "node %v is not newer", path)
	return false
}
开发者ID:klauspost,项目名称:restic,代码行数:27,代码来源:node.go

示例14: isModifiedSince

// isModifiedSince checks to see if the file has changed since the client last requested
//
// Checks for 'If-Modified-Since' header and compares timestamp against current
// timestamp of file. Returns true if the files timestamp is different to the one the
// client sent along
func isModifiedSince(req *http.Request, url string, fi os.FileInfo) bool {
	modifiedSince, msPresent := req.Header[HeaderIfModifiedSince]
	if msPresent && len(modifiedSince) > 0 {
		ms := modifiedSince[0]

		var parsedTime time.Time
		var err error
		// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html (3.3 Date/Time Formats)
		switch ms[3] {
		// RFC 822, updated by RFC 1123 - Sun, 06 Nov 1994 08:49:37 GMT
		case ',':
			parsedTime, err = time.Parse(time.RFC1123, ms)
		// ANSI C's asctime() format - Sunday, 06-Nov-94 08:49:37 GMT
		case ' ':
			parsedTime, err = time.Parse(time.ANSIC, ms)
		// RFC 850, obsoleted by RFC 1036 - Sun Nov  6 08:49:37 1994
		default:
			parsedTime, err = time.Parse(time.RFC850, ms)
		}

		// Can only continue with this if we have a valid date
		if err == nil {
			if fi.ModTime().Truncate(time.Second).Equal(parsedTime) {
				return false
			}
		}
	}
	return true
}
开发者ID:seanjohnno,项目名称:reverseproxy,代码行数:34,代码来源:handler_filesystem.go

示例15: walker

// walker implements filepath.WalkFunc.
func walker(path string, info os.FileInfo, err error) error {
	cutoff, err := time.ParseDuration(fmt.Sprintf("%dh", days*24))
	if err != nil {
		log.Fatal(err)
	}
	if time.Now().Sub(info.ModTime()) < cutoff {
		return nil
	}
	// Don't delete a directory unless it's empty.
	if info.IsDir() {
		files, err := ioutil.ReadDir(path)
		if err != nil {
			log.Fatal(err)
		}
		if len(files) > 0 {
			log.Printf("directory %s contains files; skipping\n", path)
			return nil
		}
		log.Printf("directory %s is empty\n", path)
	}
	log.Printf("deleting %s\n", path)
	if !test {
		err = os.Remove(path)
	}
	return nil
}
开发者ID:agilecreativity,项目名称:go-playground,代码行数:27,代码来源:purge.go


注:本文中的os.FileInfo.ModTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。