Fix race in ignoring non-existent files
This commit is contained in:
parent
ab04ccc0e8
commit
9e40f1c837
@ -127,15 +127,13 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
|
|||||||
func readString(dirpath string, file string) string {
|
func readString(dirpath string, file string) string {
|
||||||
cgroupFile := path.Join(dirpath, file)
|
cgroupFile := path.Join(dirpath, file)
|
||||||
|
|
||||||
// Ignore non-existent files
|
|
||||||
if !utils.FileExists(cgroupFile) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
out, err := ioutil.ReadFile(cgroupFile)
|
out, err := ioutil.ReadFile(cgroupFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("readString: Failed to read %q: %s", cgroupFile, err)
|
// Ignore non-existent files
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
glog.Errorf("readString: Failed to read %q: %s", cgroupFile, err)
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(string(out))
|
return strings.TrimSpace(string(out))
|
||||||
@ -158,13 +156,12 @@ func readUInt64(dirpath string, file string) uint64 {
|
|||||||
|
|
||||||
// Lists all directories under "path" and outputs the results as children of "parent".
|
// Lists all directories under "path" and outputs the results as children of "parent".
|
||||||
func ListDirectories(dirpath string, parent string, recursive bool, output map[string]struct{}) error {
|
func ListDirectories(dirpath string, parent string, recursive bool, output map[string]struct{}) error {
|
||||||
// Ignore if this hierarchy does not exist.
|
|
||||||
if !utils.FileExists(dirpath) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
entries, err := ioutil.ReadDir(dirpath)
|
entries, err := ioutil.ReadDir(dirpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Ignore if this hierarchy does not exist.
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
|
Loading…
Reference in New Issue
Block a user