2015-10-25 16:24:52 +00:00
|
|
|
package main
|
|
|
|
|
2016-09-17 10:36:05 +00:00
|
|
|
import (
|
|
|
|
"restic/repository"
|
2015-10-25 16:24:52 +00:00
|
|
|
|
2016-09-17 10:36:05 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2015-10-25 16:24:52 +00:00
|
|
|
|
2016-09-17 10:36:05 +00:00
|
|
|
var cmdRebuildIndex = &cobra.Command{
|
|
|
|
Use: "rebuild-index [flags]",
|
|
|
|
Short: "build a new index file",
|
|
|
|
Long: `
|
|
|
|
The "rebuild-index" command creates a new index by combining the index files
|
|
|
|
into a new one.
|
|
|
|
`,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runRebuildIndex(globalOptions)
|
|
|
|
},
|
2015-10-25 16:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-09-17 10:36:05 +00:00
|
|
|
cmdRoot.AddCommand(cmdRebuildIndex)
|
2015-10-25 16:24:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 10:36:05 +00:00
|
|
|
func runRebuildIndex(gopts GlobalOptions) error {
|
|
|
|
repo, err := OpenRepository(gopts)
|
2015-10-25 16:24:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
lock, err := lockRepoExclusive(repo)
|
|
|
|
defer unlockRepo(lock)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-11 20:30:32 +00:00
|
|
|
return repository.RebuildIndex(repo)
|
2015-10-25 16:24:52 +00:00
|
|
|
}
|