in pkg/maps/loader.go [226:266]
func (m *BpfMap) PinMap(pinPath string, pinType uint32) error {
if pinType == constdef.PIN_NONE.Index() {
return nil
}
if pinType == constdef.PIN_GLOBAL_NS.Index() {
//If pinPath is already present lets delete and create a new one
found, err := utils.IsfileExists(pinPath)
if err != nil {
return fmt.Errorf("unable to check file: %w", err)
}
if found {
log.Infof("Found file %s so deleting the path", pinPath)
err := utils.UnPinObject(pinPath)
if err != nil {
log.Errorf("failed to UnPinObject %v", err)
return err
}
}
err = os.MkdirAll(filepath.Dir(pinPath), 0755)
if err != nil {
log.Errorf("error creating directory %s: %v", filepath.Dir(pinPath), err)
return fmt.Errorf("error creating directory %s: %v", filepath.Dir(pinPath), err)
}
_, err = os.Stat(pinPath)
if err == nil {
log.Errorf("aborting, found file at %s", pinPath)
return fmt.Errorf("aborting, found file at %s", pinPath)
}
if err != nil && !os.IsNotExist(err) {
log.Errorf("failed to stat %s: %v", pinPath, err)
return fmt.Errorf("failed to stat %s: %v", pinPath, err)
}
return utils.PinObject(m.MapFD, pinPath)
}
return nil
}