MCPcopy Create free account
hub / github.com/DataDog/datadog-agent / getFileForKey

Function getFileForKey

pkg/persistentcache/persistentcache.go:23–38  ·  view source on GitHub ↗

Return a file where to store the data. We split the key by ":", using the first prefix as directory, if present. This is useful for integrations, which use the check_id formed with $check_name:$hash

(key string)

Source from the content-addressed store, hash-verified

21// first prefix as directory, if present. This is useful for integrations, which
22// use the check_id formed with $check_name:$hash
23func getFileForKey(key string) (string, error) {
24 parent := config.Datadog.GetString("run_path")
25 paths := strings.SplitN(key, ":", 2)
26 cleanedPath := invalidChars.ReplaceAllString(paths[0], "")
27 if len(paths) == 1 {
28 // If there is no colon, just return the key
29 return filepath.Join(parent, cleanedPath), nil
30 }
31 // Otherwise, create the directory with a prefix
32 err := os.MkdirAll(filepath.Join(parent, cleanedPath), 0700)
33 if err != nil {
34 return "", err
35 }
36 cleanedFile := invalidChars.ReplaceAllString(paths[1], "")
37 return filepath.Join(parent, cleanedPath, cleanedFile), nil
38}
39
40// Write stores data on disk in the run directory.
41func Write(key, value string) error {

Callers 2

WriteFunction · 0.85
ReadFunction · 0.85

Calls 2

JoinMethod · 0.80
GetStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…