Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

pkg/backup: remove unused util functions and tests. #1646

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions pkg/backup/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,93 +16,13 @@ package util

import (
"fmt"
"sort"
"strconv"
"strings"

"github.com/sirupsen/logrus"
)

func GetLatestBackupName(names []string) string {
bnames := FilterAndSortBackups(names)
if len(bnames) == 0 {
return ""
}
return bnames[len(bnames)-1]
}

func IsBackup(name string) bool {
return strings.HasSuffix(name, BackupFilenameSuffix)
}

func MakeBackupName(ver string, rev int64) string {
return fmt.Sprintf("%s_%016x_%s", ver, rev, BackupFilenameSuffix)
}

func MustParseRevision(name string) int64 {
rev, err := parseRevision(name)
if err != nil {
panic(err)
}
return rev
}

func parseRevision(name string) (int64, error) {
parts := strings.SplitN(name, "_", 3)
if len(parts) != 3 {
return 0, fmt.Errorf("bad backup name: %s", name)
}
revStr := parts[1]
rev, err := strconv.ParseInt(revStr, 16, 64)
if err != nil {
return 0, fmt.Errorf("unexpected revision string: %s, err: %v", revStr, err)
}
return rev, nil
}

func FilterAndSortBackups(names []string) []string {
bnames := make(backupNames, 0)
for _, n := range names {
if !IsBackup(n) {
continue
}
_, err := parseRevision(n)
if err != nil {
logrus.Errorf("fail to get rev from backup (%s): %v", n, err)
continue
}
bnames = append(bnames, n)
}

sort.Sort(bnames)
return []string(bnames)
}

type backupNames []string

func (bn backupNames) Len() int { return len(bn) }

func (bn backupNames) Less(i, j int) bool {
return MustParseRevision(bn[i]) < MustParseRevision(bn[j])
}

func (bn backupNames) Swap(i, j int) {
bn[i], bn[j] = bn[j], bn[i]
}

func ToMB(s int64) float64 {
n := float64(s) / (1024 * 1024)
// truncate to KB
sn := fmt.Sprintf("%.3f", n)

var err error
n, err = strconv.ParseFloat(sn, 64)
if err != nil {
panic("unexpected parse float error")
}
return n
}

// ParseBucketAndKey parses the path to return the s3 bucket name and key(path in the bucket)
// returns error if path is not in the format <s3-bucket-name>/<key>
func ParseBucketAndKey(path string) (string, string, error) {
Expand Down
85 changes: 0 additions & 85 deletions pkg/backup/util/util_test.go

This file was deleted.