LoadProgram loads or reloads a program from the full pathname programPath. The name of the program is the basename of the file.
(programPath string)
| 102 | // LoadProgram loads or reloads a program from the full pathname programPath. The name of |
| 103 | // the program is the basename of the file. |
| 104 | func (r *Runtime) LoadProgram(programPath string) error { |
| 105 | name := filepath.Base(programPath) |
| 106 | if strings.HasPrefix(name, ".") { |
| 107 | glog.V(2).Infof("Skipping %s because it is a hidden file.", programPath) |
| 108 | return nil |
| 109 | } |
| 110 | if filepath.Ext(name) != fileExt { |
| 111 | glog.V(2).Infof("Skipping %s due to file extension.", programPath) |
| 112 | return nil |
| 113 | } |
| 114 | f, err := os.OpenFile(filepath.Clean(programPath), os.O_RDONLY, 0o600) |
| 115 | if err != nil { |
| 116 | ProgLoadErrors.Add(name, 1) |
| 117 | return errors.Wrapf(err, "Failed to read program %q", programPath) |
| 118 | } |
| 119 | defer func() { |
| 120 | if err := f.Close(); err != nil { |
| 121 | glog.Warning(err) |
| 122 | } |
| 123 | }() |
| 124 | r.programErrorMu.Lock() |
| 125 | defer r.programErrorMu.Unlock() |
| 126 | r.programErrors[name] = r.CompileAndRun(name, f) |
| 127 | if r.programErrors[name] != nil { |
| 128 | if r.errorsAbort { |
| 129 | return r.programErrors[name] |
| 130 | } |
| 131 | glog.Infof("Compile errors for %s:\n%s", name, r.programErrors[name]) |
| 132 | } |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | // CompileAndRun compiles a program read from the input, starting execution if |
| 137 | // it succeeds. If an existing virtual machine of the same name already |