()
| 861 | } |
| 862 | } |
| 863 | if cfg.SystemUpdateRepoURL != protected { |
| 864 | return "", errProtectedRepoURL |
| 865 | } |
| 866 | return content, nil |
| 867 | } |
| 868 | |
| 869 | func writeConfigBackupBytes(configFile, backupDir string, content []byte) (store.BackupInfo, error) { |
| 870 | if len(content) == 0 { |
| 871 | return store.BackupInfo{}, store.ErrNotFound |
| 872 | } |
| 873 | if err := os.MkdirAll(backupDir, 0o700); err != nil { |
| 874 | return store.BackupInfo{}, err |
| 875 | } |
| 876 | now := time.Now().UTC() |
| 877 | base := strings.TrimSuffix(filepath.Base(configFile), filepath.Ext(configFile)) |
| 878 | if base == "" || base == "." { |
| 879 | base = "config" |
| 880 | } |
| 881 | name := base + "_" + now.Format("20060102_150405") + "_" + strconv.FormatInt(now.UnixNano()%1e9, 10) + ".toml" |
| 882 | path := filepath.Join(backupDir, name) |
| 883 | if err := os.WriteFile(path, content, 0o600); err != nil { |
| 884 | return store.BackupInfo{}, err |
| 885 | } |
| 886 | return store.BackupInfo{Name: name, Path: path, Size: int64(len(content)), CreatedAt: now.Unix()}, nil |
| 887 | } |
no outgoing calls
no test coverage detected