// Initializes the fields of a file and add it to a directory.
// Returns nil if successful, or an error.
969829
func (f *srvFile) Add(dir *srvFile, name string, uid User, gid Group, mode uint32, ops interface{}) error {

	lock.Lock()
	qpath := qnext
	qnext++
	lock.Unlock()

	f.Qid.Type = uint8(mode >> 24)
	f.Qid.Version = 0
	f.Qid.Path = qpath
	f.Mode = mode
	// macOS filesystem st_mtime values are only accurate to the second
	// without truncating, 9p will invent a changing fractional time #1375
	if runtime.GOOS == "darwin" {
		f.Atime = uint32(time.Now().Truncate(time.Second).Unix())
	} else {
		f.Atime = uint32(time.Now().Unix())
	}
	f.Mtime = f.Atime
	f.Length = 0
	f.Name = name
	if uid != nil {
		f.Uid = uid.Name()
		f.Uidnum = uint32(uid.Id())
	} else {
		f.Uid = "none"
		f.Uidnum = NOUID
	}

	if gid != nil {
		f.Gid = gid.Name()
		f.Gidnum = uint32(gid.Id())
	} else {
		f.Gid = "none"
		f.Gidnum = NOUID
	}

	f.Muid = ""
	f.Muidnum = NOUID
	f.Ext = ""

	if dir != nil {
		f.Parent = dir
		dir.Lock()
		for p := dir.cfirst; p != nil; p = p.next {
			if name == p.Name {
				dir.Unlock()
				return Eexist
			}
		}

		if dir.clast != nil {
			dir.clast.next = f
		} else {
			dir.cfirst = f
		}

		f.prev = dir.clast
		f.next = nil
		dir.clast = f
		dir.Unlock()
	} else {
		f.Parent = f
	}

	f.ops = ops
	return nil
}
694638
func main() {
	staticFields := make(map[string]interface{})
	staticFields["foo"] = "bar"
	baseDir := ""

	if wd, err := os.Getwd(); err != nil {
		log.Fatal(err)
	} else {
		baseDir = wd
	}

	config := bunyan.Config{
		Name: "app",
		Streams: []bunyan.Stream{
			{
				Stream: os.Stdout,
			},
			{
				Path:  filepath.Join(baseDir, "info.log"),
				Level: bunyan.LogLevelInfo,
			},
			{
				Path:  filepath.Join(baseDir, "error.log"),
				Level: bunyan.LogLevelError,
			},
		},
		StaticFields: staticFields,
	}

	if l, err := bunyan.CreateLogger(config); err != nil {
		log.Fatal(err)
	} else {
		chStatic := make(map[string]interface{})
		chStatic["baz"] = "stuff"
		c := l.Child(chStatic)

		l.Info("i am the parent %d", 100)
		c.Info("i am the child")
		l.Error(errors.New("oh no!!!"), "what happened %s", "???")
	}
}
914277
func (t *TarFile) Add(name string, file io.Reader, info os.FileInfo) error {
	var header *tar.Header
	if info == nil {
		// Unfortunately, we need to know the size for the tar header, making it necessary to read the full file into memory
		// TODO: FIXME: We could check if the io.Reader supports io.Seek, so we can do a size scan, and then seek to the beginning for the read
		buf := bytes.Buffer{}
		n, err := buf.ReadFrom(file)
		if err != nil {
			return err
		}
		header = &tar.Header{
			Name:    name,
			Size:    n,
			Mode:    0666,
			ModTime: time.Now(),
		}
		err = t.Writer.WriteHeader(header)
		if err != nil {
			return err
		}
		_, err = io.Copy(t.Writer, bytes.NewReader(buf.Bytes()))
		return err
	}

	var err error
	header, err = tar.FileInfoHeader(info, name)
	if err != nil {
		return err
	}
	err = t.Writer.WriteHeader(header)
	if err != nil {
		return err
	}
	n, err := io.Copy(t.Writer, file)
	if err != nil {
		return err
	}
	if n != info.Size() {
		return errors.New("unexpected amount of bytes copied")
	}
	return err
}
889857
func (fn FieldValueFactorFunction) Field(field string) FieldValueFactorFunction {
	fn.field = field
	return fn
}
809082
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) {
	// Append files' name together.
	fileNames := make([]string, 1, len(moreFiles)+1)
	fileNames[0] = fileName
	if len(moreFiles) > 0 {
		fileNames = append(fileNames, moreFiles...)
	}

	c = newConfigFile(fileNames)

	for _, name := range fileNames {
		if err = c.loadFile(name); err != nil {
			return nil, err
		}
	}

	return c, nil
}
1049476
func Fields(cfg *Config, words ...*syntax.Word) ([]string, error) {
	cfg = prepareConfig(cfg)
	fields := make([]string, 0, len(words))
	dir := cfg.envGet("PWD")
	for _, word := range words {
		afterBraces := []*syntax.Word{word}
		if w2 := syntax.SplitBraces(word); w2 != word {
			afterBraces = Braces(w2)
		}
		for _, word2 := range afterBraces {
			wfields, err := cfg.wordFields(word2.Parts)
			if err != nil {
				return nil, err
			}
			for _, field := range wfields {
				path, doGlob := cfg.escapedGlobField(field)
				var matches []string
				if doGlob && cfg.ReadDir != nil {
					matches, err = cfg.glob(dir, path)
					if err != nil {
						return nil, err
					}
					if len(matches) > 0 {
						fields = append(fields, matches...)
						continue
					}
				}
				fields = append(fields, cfg.fieldJoin(field))
			}
		}
	}
	return fields, nil
}
173098
func (d *FileDefer) Add(file filesystem.File) {
	d.files = append(d.files, file)
}
332311
func (self *Collection) AddFields(fields ...Field) *Collection {
	self.Fields = append(self.Fields, fields...)
	return self
}
1239922
func (s *Scanner) Init(filename string, r io.Reader, errh func(ast.Pos, error)) {
	s.r = runeReader(r)
	s.errh = errh

	s.eof = false
	s.cpos = ast.Pos{
		Filename: filename,
		Line:     1,
	}

	s.cur, s.cw = -1, 0
	s.tok.Reset()
}
761877
func AddFields(ctx context.Context, fields logrus.Fields) {
	l, ok := ctx.Value(ctxLoggerKey).(*ctxLogger)
	if !ok || l == nil {
		return
	}
	for k, v := range fields {
		l.fields[k] = v
	}
}
100985
func (f *Folder) AddFile(name string, contentType string) error {
	return f.addFile(strings.Split(name, sep), contentType)
}
658129
func (w *fileLogWriter) Init(jsonConfig string) error {
	err := json.Unmarshal([]byte(jsonConfig), w)
	if err != nil {
		return err
	}
	if len(w.Filename) == 0 {
		return errors.New("jsonconfig must have filename")
	}
	w.suffix = filepath.Ext(w.Filename)
	w.fileNameOnly = strings.TrimSuffix(w.Filename, w.suffix)
	if w.suffix == "" {
		w.suffix = ".log"
	}
	err = w.startLogger()
	return err
}
1118480
func (o *Organizer) Setup(f func()) {
	o.setup = append(o.setup, f)
}
1153258
func File(configFile string, skipNonExistent bool) *configSource {
	var from string
	if configFile == STDINFileIdentifier {
		from = "Config from STDIN"
	} else {
		from = fmt.Sprintf("Config file at '%s'", configFile)
	}
	return &configSource{
		skip: ShouldSkipFile(configFile, skipNonExistent),
		from: from,
		apply: func(baseConfig interface{}) error {
			return FromFile(configFile, baseConfig)
		},
	}
}
132524
func addFileAttribute(a *dokan.Stat, fa dokan.FileAttribute) {
	// FileAttributeNormal is valid only if no other attribute is set.
	// Thus clear the normal flag (if set) from the attributes and or
	// the new flag.
	a.FileAttributes = (a.FileAttributes &^ dokan.FileAttributeNormal) | fa
}
890288
func (f *File) Load() (*Config, error) {
	var err error
	if !utils.Exists(f.FilePath) {
		return nil, errors.New("Error: I Can't find the config file at [" + f.FilePath + "]")
	}

	// read file
	f.Data, err = ioutil.ReadFile(f.FilePath)
	if err != nil {
		return nil, err
	}

	// parse file
	return f.Parse()
}
1349873
func newFields() *fields {
	f := new(fields)
	f.fields = make(map[string]*fieldInfo)
	f.fieldsLow = make(map[string]*fieldInfo)
	f.columns = make(map[string]*fieldInfo)
	f.fieldsByType = make(map[int][]*fieldInfo)
	return f
}