~emersion/drmdb

684bd4135576236f267348d56c4fe532b460213f — Simon Ser 2 months ago 96444f0 master
Fix snapshot when running outside of repo dir
2 files changed, 19 insertions(+), 3 deletions(-)

M go.mod
M snapshot.go
M go.mod => go.mod +1 -1
@@ 1,6 1,6 @@
module git.sr.ht/~emersion/drmdb

go 1.12
go 1.16

require (
	git.sr.ht/~emersion/go-drm v0.0.0-20211215192924-f1c3744aeee0

M snapshot.go => snapshot.go +18 -2
@@ 3,6 3,7 @@ package drmdb
import (
	"archive/tar"
	"compress/gzip"
	_ "embed"
	"io"
	"io/ioutil"
	"os"


@@ 11,7 12,8 @@ import (
	"git.sr.ht/~emersion/drmdb/database"
)

const licenseFile = "LICENSE"
//go:embed LICENSE
var license string

func writeSnapshotFile(tw *tar.Writer, p string, fi os.FileInfo) error {
	f, err := os.Open(p)


@@ 40,6 42,20 @@ func writeSnapshotFile(tw *tar.Writer, p string, fi os.FileInfo) error {
	return err
}

func writeLicenseFile(tw *tar.Writer) error {
	h := tar.Header{
		Name: "LICENSE",
		Mode: 0644,
		Size: int64(len(license)),
	}
	if err := tw.WriteHeader(&h); err != nil {
		return err
	}

	_, err := io.WriteString(tw, license)
	return err
}

func writeSnapshot(w io.Writer) error {
	gw := gzip.NewWriter(w)
	defer gw.Close()


@@ 47,7 63,7 @@ func writeSnapshot(w io.Writer) error {
	tw := tar.NewWriter(gw)
	defer tw.Close()

	if err := writeSnapshotFile(tw, licenseFile, nil); err != nil {
	if err := writeLicenseFile(tw); err != nil {
		return err
	}