Ejemplo n.º 1
0
Archivo: types.go Proyecto: Byron/godi
func (s *Command) Init(numReaders, numWriters int, items []string, maxLogLevel api.Importance, filters []api.FileFilter) (err error) {
	if len(items) == 0 {
		return errors.New("Please provide at least one seal file")
	}

	validItems, err := api.ParseSources(items, true)
	if err != nil {
		return
	}

	indexDirs := make([]string, len(validItems))
	for i, index := range validItems {
		if codec := codec.NewByPath(index); codec == nil {
			return fmt.Errorf("Unknown seal file format: '%s'", index)
		}
		if _, err := os.Stat(index); err != nil {
			return fmt.Errorf("Cannot access seal file at '%s'", index)
		}
		indexDirs[i] = filepath.Dir(index)
	}

	s.InitBasicRunner(numReaders, indexDirs, maxLogLevel, filters)
	s.Items = validItems
	return nil
}
Ejemplo n.º 2
0
Archivo: types.go Proyecto: Byron/godi
func (s *Command) Generate() <-chan api.Result {
	return api.Generate(s.RootedReaders, s,
		func(trees []string, files chan<- api.FileInfo, results chan<- api.Result) {
			for _, index := range s.Items {
				// Only work in indices that are assigned to us
				found := false
				for _, tree := range trees {
					if filepath.Dir(index) == tree {
						found = true
						break
					}
				}
				if !found {
					continue
				}

				c := codec.NewByPath(index)
				if c == nil {
					panic("Should have a codec here - this was checked before")
				}

				fd, err := os.Open(index)
				if err != nil {
					results <- &VerifyResult{
						BasicResult: api.BasicResult{
							Err: &codec.DecodeError{Msg: err.Error()},
							Finfo: api.FileInfo{
								Path:     index,
								RelaPath: filepath.Base(index),
							},
						},
					}
					continue
				}

				// Figure out the path to use - for now we use the relative one
				// NOTE: We need to use the relative one as our read-controller device map is based on that.
				// If it was the absolute file path we use here, it could possibly point to a file far away,
				// in any case our read controller map will not yield the expected result unless we set it
				// up here, which is dangerous as it is async ! So let's not use the absolute path, ever !
				indexDir := filepath.Dir(index)
				err = c.Deserialize(fd, files, func(v *api.FileInfo) bool {
					select {
					case <-s.Done:
						return false
					default:
						{
							v.Path = filepath.Join(indexDir, v.RelaPath)
							return true
						}
					}
				})
				fd.Close()

				if err != nil {
					results <- &VerifyResult{
						BasicResult: api.BasicResult{
							Err: err,
							Finfo: api.FileInfo{
								Path:     index,
								RelaPath: filepath.Base(index),
							},
						},
					}
					continue
				}
			} // for each index
		})
}