Пример #1
0
// ScanToPipe ...
func ScanToPipe(fp string, pipeline *Pipeline, index indexer.Handler) error {
	filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
		if info.Name() == "." {
			return nil
		}

		if info.Name() == "" || info.Name()[0] == '.' {
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}

		if !info.IsDir() {
			reqPath, err := filepath.Rel(fp, path)
			if err != nil {
				return err
			}
			reqPath = "/" + reqPath

			if pipeline.ValidatePath(reqPath) {
				body, err := ioutil.ReadFile(path)
				if err != nil {
					return err
				}

				record := index.Record(reqPath)
				if len(body) > 0 {
					record.Write(body)
				} else {
					record.Ignore()
				}
				pipeline.Pipe(record)
			}
		}

		return nil
	})

	return nil
}
Пример #2
0
// ScanToPipe ...
func ScanToPipe(fp string, pipeline *Pipeline, index indexer.Handler) indexer.Record {
	var last indexer.Record
	absPath, _ := filepath.Abs(fp)
	filepath.Walk(absPath, func(path string, info os.FileInfo, err error) error {
		if info.Name() == "." {
			return nil
		}

		if info.Name() == "" || info.Name()[0] == '.' {
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}

		if !info.IsDir() {
			reqPath, err := filepath.Rel(absPath, path)
			if err != nil {
				return nil
			}
			reqPath = "/" + reqPath

			if pipeline.ValidatePath(reqPath) {
				record := index.Record(reqPath)
				record.SetFullPath(path)
				record.SetModified(info.ModTime())
				pipeline.Pipe(record)
				last = record
			}
		}

		return nil
	})

	return last
}