etcdmain/etcd.go
func identifyDataDirOrDie(lg *zap.Logger, dir string) dirType {
	names, err := fileutil.ReadDir(dir)
	if err != nil {
		if os.IsNotExist(err) {
			return dirEmpty
		}
		if lg != nil {
			lg.Fatal("failed to list data directory", zap.String("dir", dir), zap.Error(err))
		} else {
			plog.Fatalf("error listing data dir: %s", dir)
		}
	}

	var m, p bool
	for _, name := range names {
		switch dirType(name) {
		case dirMember:
			m = true
		case dirProxy:
			p = true
		default:
			if lg != nil {
				lg.Warn(
					"found invalid file under data directory",
					zap.String("filename", name),
					zap.String("data-dir", dir),
				)
			} else {
				plog.Warningf("found invalid file/dir %s under data dir %s (Ignore this if you are upgrading etcd)", name, dir)
			}
		}
	}

	if m && p {
		if lg != nil {
			lg.Fatal("invalid datadir; both member and proxy directories exist")
		} else {
			plog.Fatal("invalid datadir. Both member and proxy directories exist.")
		}
	}
	if m {
		return dirMember
	}
	if p {
		return dirProxy
	}
	return dirEmpty
}
func identifyDataDirOrDie(lg *zap.Logger, dir string) dirType {
	names, err := fileutil.ReadDir(dir)
	if err != nil {
		if os.IsNotExist(err) {
			return dirEmpty
		}
		if lg != nil {
			lg.Fatal("failed to list data directory", zap.String("dir", dir), zap.Error(err))
		} else {
			plog.Fatalf("error listing data dir: %s", dir)
		}
	}

	var m, p bool
	for _, name := range names {
		switch dirType(name) {
		case dirMember:
			m = true
		case dirProxy:
			p = true
		default:
			if lg != nil {
				lg.Warn(
					"found invalid file under data directory",
					zap.String("filename", name),
					zap.String("data-dir", dir),
				)
			} else {
				plog.Warningf("found invalid file/dir %s under data dir %s (Ignore this if you are upgrading etcd)", name, dir)
			}
		}
	}

	if m && p {
		if lg != nil {
			lg.Fatal("invalid datadir; both member and proxy directories exist")
		} else {
			plog.Fatal("invalid datadir. Both member and proxy directories exist.")
		}
	}
	if m {
		return dirMember
	}
	if p {
		return dirProxy
	}
	return dirEmpty
}
func identifyDataDirOrDie ( lg * zap . Logger , dir string ) dirType { names , err := fileutil . ReadDir ( dir ) if err != nil { if os . IsNotExist ( err ) { return dirEmpty } if lg != nil { lg . Fatal ( " " , zap . String ( " " , dir ) , zap . Error ( err ) ) } else { plog . Fatalf ( " " , dir ) } } var m , p bool for _ , name := range names { switch dirType ( name ) { case dirMember : m = true case dirProxy : p = true default : if lg != nil { lg . Warn ( " " , zap . String ( " " , name ) , zap . String ( " " , dir ) , ) } else { plog . Warningf ( " " , name , dir ) } } } if m && p { if lg != nil { lg . Fatal ( " " ) } else { plog . Fatal ( " " ) } } if m { return dirMember } if p { return dirProxy } return dirEmpty }
// identifyDataDirOrDie returns the type of the data dir.
// Dies if the datadir is invalid.
identifyDataDirOrDie returns the type of the data dir . Dies if the datadir is invalid .