-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update baton-sdk * Add new optimize command that optimizes a c1z on disk. * don't use fmt.Println * Use [email protected] instead of the branch
- Loading branch information
Showing
668 changed files
with
155,578 additions
and
54,259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/conductorone/baton-sdk/pkg/dotc1z/manager" | ||
"github.com/conductorone/baton-sdk/pkg/logging" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func optimizeDb() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "optimize", | ||
Short: "Optimize the c1z file. This may result in a reduction in filesize.", | ||
RunE: runOptimizeDb, | ||
Hidden: true, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runOptimizeDb(cmd *cobra.Command, args []string) error { | ||
ctx, err := logging.Init(context.Background(), logging.WithLogFormat("console"), logging.WithLogLevel("error")) | ||
if err != nil { | ||
return err | ||
} | ||
c1zPath, err := cmd.Flags().GetString("file") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
m, err := manager.New(ctx, c1zPath) | ||
if err != nil { | ||
return err | ||
} | ||
defer m.Close(ctx) | ||
|
||
store, err := m.LoadC1Z(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = store.Vacuum(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = store.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = m.SaveC1Z(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, _ = fmt.Fprintf(os.Stdout, "Optimized C1Z successfully.") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.