-
Notifications
You must be signed in to change notification settings - Fork 13
/
add.go
72 lines (60 loc) · 2.17 KB
/
add.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2016, Ben Morgan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
package main
import (
"fmt"
"github.com/cassava/repoctl/pacman"
"github.com/spf13/cobra"
)
var movePackages bool
var linkPackages bool
var addRequireSignature bool
var addNoVerify bool
func init() {
MainCmd.AddCommand(addCmd)
addCmd.Flags().BoolVarP(&movePackages, "move", "m", false, "move packages into repository")
addCmd.Flags().BoolVarP(&linkPackages, "link", "l", false, "link packages instead of copying")
addCmd.Flags().BoolVarP(&addRequireSignature, "require-signature", "r", false, "require package signatures")
addCmd.Flags().BoolVar(&addNoVerify, "no-verify", false, "don't verify packages prior to repository addition")
}
var addCmd = &cobra.Command{
Use: "add PKGFILE ...",
Short: "Copy and add packages to the repository",
Long: `Add (and copy if necessary) the package file to the repository.
Similarly to the repo-add script, this command copies the package
file to the repository (if not already there) and adds the package to
the database. Exactly this package is added to the database, this
allows you to downgrade a package in the repository.
Any other package files in the repository are deleted or backed up,
depending on whether the backup option is set. If the backup option
is set, the "obsolete" package files are moved to a backup
directory of choice.
If the backup directory resolves to the repository directory,
then obsolete package files are ignored.
`,
Example: ` repoctl add -m ./fairsplit-1.0.pkg.tar.gz`,
ValidArgsFunction: completeLocalPackageFiles,
PreRunE: ProfileInit,
PostRunE: ProfileTeardown,
RunE: func(cmd *cobra.Command, args []string) error {
if addRequireSignature {
Repo.RequireSignature = true
}
if !addNoVerify {
for _, f := range args {
_, err := pacman.Read(f)
if err != nil {
return fmt.Errorf("cannot verify package %s: %w", f, err)
}
}
}
if movePackages {
return Repo.Move(nil, args...)
}
if linkPackages {
return Repo.Link(nil, args...)
}
return Repo.Copy(nil, args...)
},
}