| 39 | } |
| 40 | |
| 41 | func createApp(unsignedFile io.Reader, name string, profile Profile, signArgs string, userBundleId string, builderId string, tweakMap map[string]io.Reader) (App, error) { |
| 42 | app := newApp(uuid.NewString()) |
| 43 | if err := os.MkdirAll(app.resolvePath(AppRoot), os.ModePerm); err != nil { |
| 44 | return nil, errors.New("make app dir") |
| 45 | } |
| 46 | pairs := map[FSName]string{ |
| 47 | AppName: name, |
| 48 | AppSignArgs: signArgs, |
| 49 | AppUserBundleId: userBundleId, |
| 50 | AppBuilderId: builderId, |
| 51 | AppProfileId: profile.GetId(), |
| 52 | } |
| 53 | for fileType, value := range pairs { |
| 54 | if err := app.SetString(fileType, value); err != nil { |
| 55 | return nil, errors.WithMessagef(err, "set %s", fileType) |
| 56 | } |
| 57 | } |
| 58 | if err := app.SetFile(AppUnsignedFile, unsignedFile); err != nil { |
| 59 | return nil, errors.WithMessagef(err, "set %s", AppUnsignedFile) |
| 60 | } |
| 61 | if len(tweakMap) > 0 { |
| 62 | if err := app.MkDir(TweaksDir); err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | } |
| 66 | for name, tweak := range tweakMap { |
| 67 | tweakPath := FSName(util.SafeJoinFilePaths(string(TweaksDir), name)) |
| 68 | if err := app.SetFile(tweakPath, tweak); err != nil { |
| 69 | return nil, errors.WithMessagef(err, "set %s", tweakPath) |
| 70 | } |
| 71 | } |
| 72 | return app, nil |
| 73 | } |
| 74 | |
| 75 | func newApp(id string) *app { |
| 76 | return &app{id: id, FileSystemBase: FileSystemBase{resolvePath: func(name FSName) string { |