Last active
December 29, 2020 18:33
-
-
Save aarnaud/6fcec8238f37fe067d722aae512e1e8b to your computer and use it in GitHub Desktop.
debug-windows-stat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"path/filepath" | |
) | |
func removeContents(dir string) error { | |
d, err := os.Open(dir) | |
if err != nil { | |
fmt.Printf("Failed open dir: %v", err) | |
return err | |
} | |
defer d.Close() | |
names, err := d.Readdirnames(-1) | |
if err != nil { | |
fmt.Printf("Failed readdirnames: %v", err) | |
return err | |
} | |
var errs []error | |
for _, name := range names { | |
filePath := filepath.Join(dir, name) | |
fmt.Printf("process file %s", filePath) | |
stat, err := os.Lstat(filePath) | |
if err != nil { | |
fmt.Printf("Failed to stat file %s: %v", filePath, err) | |
continue | |
} | |
if stat.IsDir() { | |
continue | |
} | |
err = os.RemoveAll(filePath) | |
if err != nil { | |
errs = append(errs, err) | |
fmt.Printf("Failed to remove file %s: %v", filePath, err) | |
continue | |
} | |
} | |
return nil | |
} | |
func main() { | |
socketdir := "\\var\\lib\\kubelet\\device-plugins" | |
socketname := "kubelet.sock" | |
socketPath := filepath.Join(socketdir, socketname) | |
if err := os.MkdirAll(socketdir, 0750); err != nil { | |
fmt.Printf(err.Error()) | |
os.Exit(1) | |
} | |
removeContents(socketdir) | |
_, err := net.Listen("unix", socketPath) | |
if err != nil { | |
fmt.Printf(" %v", err) | |
os.Exit(1) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"path/filepath" | |
) | |
func removeContents(dir string) error { | |
d, err := os.Open(dir) | |
if err != nil { | |
fmt.Printf("Failed open dir: %v", err) | |
return err | |
} | |
defer d.Close() | |
names, err := d.Readdirnames(-1) | |
if err != nil { | |
fmt.Printf("Failed readdirnames: %v", err) | |
return err | |
} | |
var errs []error | |
for _, name := range names { | |
filePath := filepath.Join(dir, name) | |
fmt.Printf("process file %s", filePath) | |
stat, err := os.Stat(filePath) | |
if err != nil { | |
fmt.Printf("Failed to stat file %s: %v", filePath, err) | |
continue | |
} | |
if stat.IsDir() { | |
continue | |
} | |
err = os.RemoveAll(filePath) | |
if err != nil { | |
errs = append(errs, err) | |
fmt.Printf("Failed to remove file %s: %v", filePath, err) | |
continue | |
} | |
} | |
return nil | |
} | |
func main() { | |
socketdir := "\\var\\lib\\kubelet\\device-plugins" | |
socketname := "kubelet.sock" | |
socketPath := filepath.Join(socketdir, socketname) | |
if err := os.MkdirAll(socketdir, 0750); err != nil { | |
fmt.Printf(err.Error()) | |
os.Exit(1) | |
} | |
removeContents(socketdir) | |
_, err := net.Listen("unix", socketPath) | |
if err != nil { | |
fmt.Printf(" %v", err) | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment