Example #1
2
func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
	if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
		link, err := filepath.EvalSymlinks(filePath)
		if err != nil {
			jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
			return false, nil
		}
		linkfi, err := os.Stat(link)
		if err != nil {
			jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
			return false, nil
		}
		if !linkfi.Mode().IsRegular() {
			jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
		}
		return false, nil
	}

	if fi.IsDir() {
		if f.avoid(filePath) || isNonProcessablePath(filePath) {
			return false, filepath.SkipDir
		}
		return false, nil
	}

	if isNonProcessablePath(filePath) {
		return false, nil
	}
	return true, nil
}
Example #2
1
func (daemon *Daemon) mountVolumes(container *Container) error {
	mounts, err := daemon.setupMounts(container)
	if err != nil {
		return err
	}

	for _, m := range mounts {
		dest, err := container.GetResourcePath(m.Destination)
		if err != nil {
			return err
		}

		var stat os.FileInfo
		stat, err = os.Stat(m.Source)
		if err != nil {
			return err
		}
		if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil {
			return err
		}

		opts := "rbind,ro"
		if m.Writable {
			opts = "rbind,rw"
		}

		if err := mount.Mount(m.Source, dest, "bind", opts); err != nil {
			return err
		}
	}

	return nil
}
// bumpWalk walks the third_party directory and bumps all of the packages that it finds.
func bumpWalk(path string, info os.FileInfo, err error) error {
	if err != nil {
		return nil
	}

	// go packages are always directories
	if info.IsDir() == false {
		return nil
	}

	parts := strings.Split(path, srcDir()+"/")
	if len(parts) == 1 {
		return nil
	}

	pkg := parts[1]

	if validPkg(pkg) == false {
		return nil
	}

	bump(pkg, "")

	return nil
}
Example #4
0
// Walk recursively iterates over all files in a directory and processes any
// file that imports "github.com/boltdb/raw".
func walk(path string, info os.FileInfo, err error) error {
	traceln("walk:", path)

	if info == nil {
		return fmt.Errorf("file not found: %s", err)
	} else if info.IsDir() {
		traceln("skipping: is directory")
		return nil
	} else if filepath.Ext(path) != ".go" {
		traceln("skipping: is not a go file")
		return nil
	}

	// Check if file imports boltdb/raw.
	if v, err := importsRaw(path); err != nil {
		return err
	} else if !v {
		traceln("skipping: does not import raw")
		return nil
	}

	// Process each file.
	if err := process(path); err != nil {
		return err
	}

	return nil
}
Example #5
0
func fileInfoNameFunc(fi os.FileInfo) string {
	name := fi.Name()
	if fi.IsDir() {
		name += "/"
	}
	return name
}
Example #6
0
File: i18n.go Project: revel/revel
// Load a single message file
func loadMessageFile(path string, info os.FileInfo, osError error) error {
	if osError != nil {
		return osError
	}
	if info.IsDir() {
		return nil
	}

	if matched, _ := regexp.MatchString(messageFilePattern, info.Name()); matched {
		if config, error := parseMessagesFile(path); error != nil {
			return error
		} else {
			locale := parseLocaleFromFileName(info.Name())

			// If we have already parsed a message file for this locale, merge both
			if _, exists := messages[locale]; exists {
				messages[locale].Merge(config)
				TRACE.Printf("Successfully merged messages for locale '%s'", locale)
			} else {
				messages[locale] = config
			}

			TRACE.Println("Successfully loaded messages from file", info.Name())
		}
	} else {
		TRACE.Printf("Ignoring file %s because it did not have a valid extension", info.Name())
	}

	return nil
}
Example #7
0
File: pack.go Project: Linvas/ant
func (wft *walkFileTree) walkLeaf(fpath string, fi os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	if fpath == outputP {
		return nil
	}

	if fi.IsDir() {
		return nil
	}

	if ssym && fi.Mode()&os.ModeSymlink > 0 {
		return nil
	}

	name := wft.virPath(fpath)

	if wft.allfiles[name] {
		return nil
	}

	if added, err := wft.wak.compress(name, fpath, fi); added {
		if verbose {
			fmt.Printf("Compressed: %s\n", name)
		}
		wft.allfiles[name] = true
		return err
	} else {
		return err
	}
}
Example #8
0
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
}
Example #9
0
func walkdir(path string, f os.FileInfo, err error) error {
	fmt.Printf("Visited: %s\n", path)
	if f.IsDir() == false {
		output = inspectfile(path, output)
	}
	return nil
}
Example #10
0
func deriveFolderName(path string, info os.FileInfo) string {
	if info.IsDir() {
		return path
	} else {
		return filepath.Dir(path)
	}
}
// visit a file path
// if the file is a .pb.go (protobuf file), call the parse function and add result to output
func visit(currentPath string, f os.FileInfo, err error) error {
	fmt.Printf("Visited: %s\n", currentPath)
	if !f.IsDir() {
		var fileName = f.Name()
		var strLen = len(fileName)
		if strLen >= len(DEFAULT_EXTENSION) && fileName[strLen-len(DEFAULT_EXTENSION):strLen] == DEFAULT_EXTENSION {
			absPath, err1 := filepath.Abs(currentPath)
			if err1 == nil {
				importPath := filepath.Dir(absPath)
				if importPath[0:len(goPath)] == goPath {
					importPath = importPath[len(goPath):len(importPath)]
				}
				srcIndex := strings.Index(importPath, SRC_DIR)
				importPath = importPath[srcIndex+len(SRC_DIR) : len(importPath)]
				fmt.Printf("file path from go path: %d %s\n", srcIndex, importPath)

				result := parseProtobufFile(absPath, importPath)

				if !output.ImportPath[result.ImportPath] {
					// add import path to output
					output.ImportPath[result.ImportPath] = true
				}
				for key, dataType := range result.Types {
					if _, ok := output.Types[key]; !ok {
						output.Types[key] = dataType
					}
				}
			}
		}
	}
	return err
}
Example #12
0
// StreamFile streams a file or directory entry into StreamArchive.
func (s *StreamArchive) StreamFile(relPath string, fi os.FileInfo, data []byte) error {
	if fi.IsDir() {
		fh, err := zip.FileInfoHeader(fi)
		if err != nil {
			return err
		}
		fh.Name = relPath + "/"
		if _, err = s.Writer.CreateHeader(fh); err != nil {
			return err
		}
	} else {
		fh, err := zip.FileInfoHeader(fi)
		if err != nil {
			return err
		}
		fh.Name = filepath.Join(relPath, fi.Name())
		fh.Method = zip.Deflate
		fw, err := s.Writer.CreateHeader(fh)
		if err != nil {
			return err
		} else if _, err = fw.Write(data); err != nil {
			return err
		}
	}
	return nil
}
Example #13
0
File: rules.go Project: runseb/helm
// Ignore evalutes the file at the given path, and returns true if it should be ignored.
//
// Ignore evaluates path against the rules in order. Evaluation stops when a match
// is found. Matching a negative rule will stop evaluation.
func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
	for _, p := range r.patterns {
		if p.match == nil {
			log.Printf("ignore: no matcher supplied for %q", p.raw)
			return false
		}

		// For negative rules, we need to capture and return non-matches,
		// and continue for matches.
		if p.negate {
			if p.mustDir && !fi.IsDir() {
				return true
			}
			if !p.match(path, fi) {
				return true
			}
			continue
		}

		// If the rule is looking for directories, and this is not a directory,
		// skip it.
		if p.mustDir && !fi.IsDir() {
			continue
		}
		if p.match(path, fi) {
			return true
		}
	}
	return false
}
Example #14
0
func list(path string, info os.FileInfo, node *fsNode, n *int) error {
	if (!info.IsDir() && !info.Mode().IsRegular()) || strings.HasPrefix(info.Name(), ".") {
		return errors.New("Non-regular file")
	}
	(*n)++
	if (*n) > fileNumberLimit {
		return errors.New("Over file limit") //limit number of files walked
	}
	node.Name = info.Name()
	node.Size = info.Size()
	node.Modified = info.ModTime()
	if !info.IsDir() {
		return nil
	}
	children, err := ioutil.ReadDir(path)
	if err != nil {
		return fmt.Errorf("Failed to list files")
	}
	node.Size = 0
	for _, i := range children {
		c := &fsNode{}
		p := filepath.Join(path, i.Name())
		if err := list(p, i, c, n); err != nil {
			continue
		}
		node.Size += c.Size
		node.Children = append(node.Children, c)
	}
	return nil
}
Example #15
0
func (self *Watcher) includeFolders(path string, info os.FileInfo, err error) error {
	if info.IsDir() {
		log.Println("Including:", path)
		self.watched[path] = contract.NewPackage(path)
	}
	return nil
}
Example #16
0
func (x *Generator) addPath(parent string, prefix string, info os.FileInfo) error {
	p := path.Join(parent, info.Name())

	f := file{
		info: info,
		path: path.Join(prefix, p),
	}

	x.fsFilesMap[p] = f

	if info.IsDir() {
		f, err := os.Open(f.path)
		fi, err := f.Readdir(-1)
		f.Close()
		if err != nil {
			return err
		}

		x.fsDirsMap[p] = make([]string, 0, len(fi))

		for _, f := range fi {
			if err := x.addPath(p, prefix, f); err != nil {
				return err
			}
		}
	} else {
		x.appendFileInDir(parent, info.Name())
	}

	return nil
}
Example #17
0
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
}
Example #18
0
// getRealName - gets the proper filename for sorting purposes
// Readdir() filters out directory names without separators, add
// them back for proper sorting results.
func getRealName(info os.FileInfo) string {
	if info.IsDir() {
		// Make sure directory has its end separator.
		return info.Name() + string(os.PathSeparator)
	}
	return info.Name()
}
Example #19
0
// walk recursively descends path, calling w.
func walk(path string, info os.FileInfo, walkFn WalkFunc) error {
	err := walkFn(path, info, nil)
	if err != nil {
		if info.IsDir() && err == SkipDir {
			return nil
		}
		return err
	}

	if !info.IsDir() {
		return nil
	}

	list, err := readDir(path)
	if err != nil {
		return walkFn(path, info, err)
	}

	for _, fileInfo := range list {
		err = walk(Join(path, fileInfo.Name()), fileInfo, walkFn)
		if err != nil {
			if !fileInfo.IsDir() || err != SkipDir {
				return err
			}
		}
	}
	return nil
}
Example #20
0
// Prints the filesystem to stdout, useful for testing.
// Not part of the filesystem interface.
func (mf *MockFilesystem) Print() {
	var (
		dirs   []string
		lines  [][]interface{}
		path   string
		f      File
		fi     os.FileInfo
		files  []os.FileInfo
		maxlen int
	)
	dirs = append(dirs, "/")
	maxlen = 1
	for len(dirs) > 0 {
		path = dirs[0]
		dirs = dirs[1:]
		f, _ = mf.Open(path)
		fi, _ = f.Stat()
		files, _ = f.Readdir(100)
		for _, fi = range files {
			name := filepath.Join(path, fi.Name())
			line := []interface{}{name, fi.Mode(), fi.IsDir()}
			lines = append(lines, line)
			if len(name) > maxlen {
				maxlen = len(name)
			}
			if fi.IsDir() {
				dirs = append(dirs, name)
			}
		}
	}
	fmtstr := fmt.Sprintf("%%-%vv %%v %%v\n", maxlen)
	for _, line := range lines {
		fmt.Printf(fmtstr, line[0], line[1], line[2])
	}
}
Example #21
0
func dir2Npmode(d os.FileInfo, dotu bool) uint32 {
	ret := uint32(d.Mode() & 0777)
	if d.IsDir() {
		ret |= p.DMDIR
	}

	if dotu {
		mode := d.Mode()
		if mode&os.ModeSymlink != 0 {
			ret |= p.DMSYMLINK
		}

		if mode&os.ModeSocket != 0 {
			ret |= p.DMSOCKET
		}

		if mode&os.ModeNamedPipe != 0 {
			ret |= p.DMNAMEDPIPE
		}

		if mode&os.ModeDevice != 0 {
			ret |= p.DMDEVICE
		}

		if mode&os.ModeSetuid != 0 {
			ret |= p.DMSETUID
		}

		if mode&os.ModeSetgid != 0 {
			ret |= p.DMSETGID
		}
	}

	return ret
}
Example #22
0
func showVCSDirs(path string, info os.FileInfo, err error) error {
	if err != nil {
		log.Printf("%s: %s", path, err)
		return nil
	}
	if !info.IsDir() {
		return nil
	}
	for _, v := range vcs {
		for _, m := range v.match {
			f, err := os.Stat(filepath.Join(path, m))
			if err != nil {
				continue
			}
			if !f.IsDir() {
				continue
			}
			if !hide(path) {
				fmt.Fprintf(out, "%-3s %s\n", v.name, path)
			}
			return filepath.SkipDir
		}
	}
	return nil
}
Example #23
0
func (show *Slideshow) walkSlideshow(localpath string, info os.FileInfo, err error) error {

	if err != nil {
		return err
	}

	if info.IsDir() {
		return nil
	}

	ext := filepath.Ext(localpath)
	ext = strings.ToLower(ext)

	if ext == ".jpg" {

		photo := new(SlideshowPhoto)
		photo.path = localpath
		photo.Photo = path.Join("/slideshow", info.Name())
		photo.Timestamp = info.ModTime() //info.ModTime().Format(time.RFC3339)

		show.Photos = append(show.Photos, photo)

	}

	return nil

}
Example #24
0
func (t *Templates) parseFile(path string, f os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	ext := filepath.Ext(f.Name())
	if f.IsDir() || !t.check(ext) {
		return nil
	}

	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

	contents, err := ioutil.ReadAll(file)
	if err != nil {
		return err
	}

	subPath := strings.Replace(path, t.stripPrefix, "", 1)
	if strings.Contains(path, "/view/") || strings.Contains(path, "/views/") {
		t.views[subPath] = string(contents)
	} else {
		t.partials[subPath] = string(contents)
	}

	return nil
}
Example #25
0
File: flatfs.go Project: rht/bssim
func (fs *Datastore) enumerateKeys(fi os.FileInfo, res []query.Entry) ([]query.Entry, error) {
	if !fi.IsDir() || fi.Name()[0] == '.' {
		return res, nil
	}
	child, err := os.Open(path.Join(fs.path, fi.Name()))
	if err != nil {
		return nil, err
	}
	defer child.Close()
	objs, err := child.Readdir(0)
	if err != nil {
		return nil, err
	}
	for _, fi := range objs {
		if !fi.Mode().IsRegular() || fi.Name()[0] == '.' {
			return res, nil
		}
		key, ok := fs.decode(fi.Name())
		if !ok {
			return res, nil
		}
		res = append(res, query.Entry{Key: key.String()})
	}
	return res, nil
}
Example #26
0
func StitchWalk(path string, info os.FileInfo, err error) error {
	fmt.Println(path, info, err)
	if info.IsDir() {
		fmt.Println("Is a dir")
	} else {
		/*
		   f0, err0 := os.Open(path)
		   if err0 != nil {
		       return err0
		   }
		*/
		fmt.Printf("writing %s. %v bytes", path, info.Size())
		b0, err0 := ioutil.ReadFile(path)
		if err0 != nil {
			return err0
		}
		s0 := string(b0)
		// s1 := fmt.Sprintf("%s,\n", s0)
		s1 := info.Name()
		s1 = s1[:len(s1)-5]
		s2 := fmt.Sprintf("%s:%s,\n", s1, s0)
		W.WriteString(s2)
	}
	return err
}
Example #27
0
func (t *tarRenderer) Walk(path string, finfo os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	fh, err := tar.FileInfoHeader(finfo, "")
	if err != nil {
		return err
	}

	fh.Name = "download/" + path
	err = t.w.WriteHeader(fh)
	if err != nil {
		return err
	}

	if finfo.IsDir() {
		return nil
	}

	f, err := os.Open(filepath.Join(t.root, path))
	if err != nil {
		return err
	}
	defer f.Close()

	_, err = io.Copy(t.w, f)
	return err
}
Example #28
0
func tarDir(srcBase, srcRelative string, tw *tar.Writer, fi os.FileInfo) (err error) {
	srcFull := srcBase + srcRelative
	fis, er := ioutil.ReadDir(srcFull)
	if er != nil {
		return er
	}

	for _, fi := range fis {
		if fi.IsDir() {
			tarDir(srcBase, srcRelative+"/"+fi.Name(), tw, fi)
		} else {
			tarFile(srcBase, srcRelative+"/"+fi.Name(), tw, fi)
		}
	}

	if len(srcRelative) > 0 {
		hdr, er := tar.FileInfoHeader(fi, "")
		if er != nil {
			return er
		}
		hdr.Name = srcRelative
		if er = tw.WriteHeader(hdr); er != nil {
			return er
		}
	}

	return nil
}
Example #29
0
// checkWalk is a helper function to sanity check for *.wsp files in a
// file tree walk.  If the file is valid, normal *.wsp nil is returned.
// Otherwise a non-nil error value is returned.
func checkWalk(path string, info os.FileInfo, err error) (bool, error) {
	// Did the Walk function hit an error on this file?
	if err != nil {
		log.Printf("%s\n", err)
		// File perm or exists error, log and skip
		return false, nil
	}

	// Sanity check our file
	if info.IsDir() {
		// Ignore dot-files and dot-directories
		if strings.HasPrefix(info.Name(), ".") {
			return false, filepath.SkipDir
		}
		return false, nil
	}
	if !info.Mode().IsRegular() {
		// Not a regular file
		return false, nil
	}
	if !strings.HasSuffix(path, ".wsp") {
		// Not a Whisper Database
		return false, nil
	}

	return true, nil
}
Example #30
0
func downloadsWalkFunc(fullPath string, Version string, fi2 os.FileInfo, err error, tp TaskParams, report Report, reportFilename, format string) error {
	if fi2.IsDir() || fi2.Name() == reportFilename {
		return nil
	}

	versionDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())
	relativePath := strings.Replace(fullPath, versionDir, "", -1)
	relativePath = strings.TrimPrefix(relativePath, "/")
	text := fi2.Name()
	if format == "markdown" {
		text = strings.Replace(text, "_", "\\_", -1)
	}
	category := GetCategory(relativePath)

	//log.Printf("Adding: %s", relativePath)
	download := Download{text, Version, relativePath}
	v, ok := report.Categories[category]
	var existing []Download
	if !ok {
		existing = []Download{}
	} else {
		existing = *v
	}

	existing = append(existing, download)
	report.Categories[category] = &existing
	//entryCount++
	return nil
}