Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2024-12-29 09:19:24 +01:00
parent 017659a86c
commit bed521a65d
No known key found for this signature in database
7 changed files with 90 additions and 6 deletions

View file

@ -1,5 +1,7 @@
# zerkalo
A tool to efficiently mirror Linux distribution repositories (and perhaps some other forms of repositories). Uses a [git](https://git-scm.com/)-alike blob storage for data allowing for cheap snapshotting of repositories.
## Name
The name zerkalo comes from the Russian [зеркало](https://en.wiktionary.org/wiki/%D0%B7%D0%B5%D1%80%D0%BA%D0%B0%D0%BB%D0%BE) which is a mirror.

View file

@ -6,14 +6,14 @@ import (
var (
// Used for flags.
userLicense string
storagePath string
rootCmd = &cobra.Command{
Use: "zerkalo",
Short: "",
//Long: `Cobra is a CLI library for Go that empowers applications.
//This application is a tool to generate the needed files
//to quickly create a Cobra application.`,
Short: "Efficiently mirror Linux distribution repositories",
Long: `zerkalo is a CLI program that allows its users to mirror.
Linux distribution repositories such as apt, or yum. It lets users easily
snapshot repositories per day and deduplicates as much content as it can.`,
}
)
@ -23,5 +23,5 @@ func Execute() error {
}
func init() {
// rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
rootCmd.PersistentFlags().StringVarP(&storagePath, "storage-path", "p", "", "zerkalo storage path")
}

20
cmd/storage.go Normal file
View file

@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(storageCmd)
}
var storageCmd = &cobra.Command{
Use: "storage",
Short: "Interact with the storage used by zerkalo",
//Long: `All software has versions. This is Hugo's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hugo Static Site Generator v0.9 -- HEAD")
},
}

View file

@ -0,0 +1 @@
package yum

View file

View file

View file

@ -0,0 +1,61 @@
package storage
import (
"crypto/sha256"
)
type Storage struct {
Path string
}
func NewStorage(path string) (*Storage, error) {
s := Storage{
Path: path,
}
return &s, nil
}
type Object interface {
GetHash() [32]byte
}
type Blob struct {
Data []byte
}
// The `GetHash()` for a `Blob` is a straightforward SHA256 hash of the
// contents of that blob.
func (b *Blob) GetHash() [32]byte {
return sha256.Sum256(b.Data)
}
func NewBlob(data []byte) (*Blob, error) {
b := Blob{
Data: data,
}
return &b, nil
}
type Tree struct {
Items map[string]Object
}
func NewTree() (*Tree, error) {
return nil, nil
}
// For a `Tree` the `GetHash()` is a bit more intertwined. It's basically the
// hash of all its items. Yes, this recurses trees which is bad but the naive
// approach suffices for now. I also don't like the `[32]` vs `[]` dance here.
func (t *Tree) GetHash() [32]byte {
h := sha256.New()
for _, v := range t.Items {
s := v.GetHash()
h.Write(s[:])
}
return [32]byte(h.Sum(nil))
}