add left pack algo

This commit is contained in:
2024-06-06 20:14:18 -06:00
parent b3bbd2e5d1
commit 2ed1b06f5e
3 changed files with 121 additions and 5 deletions

View File

@ -28,6 +28,18 @@ func plan() *cli.Command {
Aliases: []string{"v"},
Value: false,
},
&cli.BoolFlag{
Name: "left-pack",
Usage: "Use the left-pack algorithm to calculate partitions",
Aliases: []string{"l"},
Value: false,
},
&cli.BoolFlag{
Name: "reset",
Usage: "Reset the database before planning partitions",
Aliases: []string{"r"},
Value: false,
},
},
Action: func(c *cli.Context) error {
@ -42,6 +54,13 @@ func plan() *cli.Command {
panic(fmt.Errorf("error migrating db: %w", err))
}
if c.Bool("reset") {
err = store.RemovePartitionAssignment()
if err != nil {
return fmt.Errorf("error resetting partitions in the db: %w", err)
}
}
size := int64(4600000000) // size of a single layer DVD
targetSize := c.String("targetSize")
switch targetSize {
@ -76,9 +95,20 @@ func plan() *cli.Command {
fmt.Printf("Target Size: %v\n", humanize.Bytes(uint64(size)))
fmt.Println("Calculating partitions...")
partitions, err := partitioner.CalculatePartitions(store, size)
if err != nil {
return fmt.Errorf("error calculating partitions: %w", err)
var partitions [][]types.FileMetadata
if !c.Bool("left-pack") {
partitions, err = partitioner.CalculatePartitions(store, size)
if err != nil {
return fmt.Errorf("error calculating partitions: %w", err)
}
}
if c.Bool("left-pack") {
partitions, err = partitioner.CalculatePartitionsLeftPack(store, size)
if err != nil {
return fmt.Errorf("error calculating partitions: %w", err)
}
}
for i, partition := range partitions {