MCPcopy Create free account
hub / github.com/containerd/nerdctl / Init

Method Init

pkg/logging/json_logger.go:65–82  ·  view source on GitHub ↗
(dataStore, ns, id string)

Source from the content-addressed store, hash-verified

63}
64
65func (jsonLogger *JSONLogger) Init(dataStore, ns, id string) error {
66 // Initialize the log file (https://github.com/containerd/nerdctl/issues/1071)
67 var jsonFilePath string
68 if logPath, ok := jsonLogger.Opts[LogPath]; ok {
69 jsonFilePath = logPath
70 } else {
71 jsonFilePath = jsonfile.Path(dataStore, ns, id)
72 }
73 if err := os.MkdirAll(filepath.Dir(jsonFilePath), 0700); err != nil {
74 return err
75 }
76 if _, err := os.Stat(jsonFilePath); errors.Is(err, os.ErrNotExist) {
77 if writeErr := filesystem.WriteFile(jsonFilePath, []byte{}, 0600); writeErr != nil {
78 return writeErr
79 }
80 }
81 return nil
82}
83
84func (jsonLogger *JSONLogger) PreProcess(ctx context.Context, dataStore string, config *logging.Config) error {
85 var jsonFilePath string

Callers

nothing calls this directly

Calls 4

PathFunction · 0.92
WriteFileFunction · 0.92
StatMethod · 0.80
DirMethod · 0.65

Tested by

no test coverage detected