(localAppId string)
| 177 | } |
| 178 | |
| 179 | func MakeDraftFromLocal(localAppId string) (string, error) { |
| 180 | if err := ValidateAppId(localAppId); err != nil { |
| 181 | return "", fmt.Errorf("invalid appId: %w", err) |
| 182 | } |
| 183 | |
| 184 | appNS, appName, _ := ParseAppId(localAppId) |
| 185 | if appNS != AppNSLocal { |
| 186 | return "", fmt.Errorf("appId must be in local namespace, got: %s", appNS) |
| 187 | } |
| 188 | |
| 189 | localDir, err := GetAppDir(localAppId) |
| 190 | if err != nil { |
| 191 | return "", err |
| 192 | } |
| 193 | |
| 194 | if _, err := os.Stat(localDir); os.IsNotExist(err) { |
| 195 | return "", fmt.Errorf("local app does not exist: %s", localDir) |
| 196 | } |
| 197 | |
| 198 | draftAppId := MakeAppId(AppNSDraft, appName) |
| 199 | draftDir, err := GetAppDir(draftAppId) |
| 200 | if err != nil { |
| 201 | return "", err |
| 202 | } |
| 203 | |
| 204 | if _, err := os.Stat(draftDir); err == nil { |
| 205 | // draft already exists, don't overwrite (that's what RevertDraft is for) |
| 206 | return draftAppId, nil |
| 207 | } else if !os.IsNotExist(err) { |
| 208 | return "", err |
| 209 | } |
| 210 | |
| 211 | if err := copyDir(localDir, draftDir); err != nil { |
| 212 | return "", err |
| 213 | } |
| 214 | |
| 215 | return draftAppId, nil |
| 216 | } |
| 217 | |
| 218 | func DeleteApp(appId string) error { |
| 219 | if err := ValidateAppId(appId); err != nil { |
no test coverage detected