createConfigFile attempts to avoid creating a config file on linux or freebsd. It used to avoid it when running on macos from homebrew, but not anymore.
(file string)
| 187 | // createConfigFile attempts to avoid creating a config file on linux or freebsd. |
| 188 | // It used to avoid it when running on macos from homebrew, but not anymore. |
| 189 | func (u *Unpackerr) createConfigFile(file string) (string, error) { |
| 190 | if isRunningInDocker() { |
| 191 | if stat, err := os.Stat("/config"); err == nil && stat.IsDir() { |
| 192 | file = "/config/unpackerr.conf" |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if file == "" { |
| 197 | return "", nil |
| 198 | } |
| 199 | |
| 200 | file, err := filepath.Abs(expandHomedir(file)) |
| 201 | if err != nil { |
| 202 | return "", fmt.Errorf("absolute file: %w", err) |
| 203 | } |
| 204 | |
| 205 | dir := filepath.Dir(file) |
| 206 | if err := os.MkdirAll(dir, logsDirMode); err != nil { |
| 207 | return "", fmt.Errorf("making config dir: %w", err) |
| 208 | } |
| 209 | |
| 210 | fOpen, err := os.Create(file) |
| 211 | if err != nil { |
| 212 | return "", fmt.Errorf("creating config file: %w", err) |
| 213 | } |
| 214 | defer fOpen.Close() |
| 215 | |
| 216 | if _, err = fOpen.Write(examples.ConfigFile); err != nil { |
| 217 | return "", fmt.Errorf("writing config file: %w", err) |
| 218 | } |
| 219 | |
| 220 | if err := cnfgfile.Unmarshal(u.Config, file); err != nil { |
| 221 | return file, fmt.Errorf("config file: %w", err) |
| 222 | } |
| 223 | |
| 224 | return file, nil |
| 225 | } |
| 226 | |
| 227 | // This function checks if rar passwords need to be read from a file path. |
| 228 | // Only runs once at startup to load passwords into memory. |
no test coverage detected