Better tmpfs mode

This commit is contained in:
Mustafa Gezen 2021-03-18 18:44:02 +01:00
parent 8db8d6204f
commit 49a37518bc
4 changed files with 30 additions and 31 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/plumbing/transport/ssh" "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"io/ioutil"
"log" "log"
"os" "os"
"os/user" "os/user"
@ -38,7 +37,7 @@ var (
singleTag string singleTag string
noDupMode bool noDupMode bool
moduleMode bool moduleMode bool
tmpFsMode bool tmpFsMode string
noStorageDownload bool noStorageDownload bool
noStorageUpload bool noStorageUpload bool
) )
@ -96,20 +95,17 @@ func mn(_ *cobra.Command, _ []string) {
log.Fatalf("could not get git authenticator: %v", err) log.Fatalf("could not get git authenticator: %v", err)
} }
fsCreator := func() billy.Filesystem { fsCreator := func(branch string) billy.Filesystem {
return memfs.New() return memfs.New()
} }
if tmpFsMode { if tmpFsMode != "" {
tmpBaseDir, err := ioutil.TempDir(os.TempDir(), "srpmproc-*") log.Printf("using tmpfs dir: %s", tmpFsMode)
fsCreator = func(branch string) billy.Filesystem {
tmpDir := filepath.Join(tmpFsMode, branch)
err := os.MkdirAll(tmpDir, 0755)
if err != nil { if err != nil {
log.Fatalf("could not create temp dir: %v", err) log.Fatalf("could not create tmpfs dir: %v", err)
}
log.Printf("using temp dir: %s", tmpBaseDir)
fsCreator = func() billy.Filesystem {
tmpDir, err := ioutil.TempDir(tmpBaseDir, "*")
if err != nil {
log.Fatalf("could not create temp dir: %v", err)
} }
return osfs.New(tmpDir) return osfs.New(tmpDir)
} }
@ -160,7 +156,7 @@ func main() {
root.Flags().StringVar(&singleTag, "single-tag", "", "If set, only this tag is imported") root.Flags().StringVar(&singleTag, "single-tag", "", "If set, only this tag is imported")
root.Flags().BoolVar(&noDupMode, "no-dup-mode", false, "If enabled, skips already imported tags") root.Flags().BoolVar(&noDupMode, "no-dup-mode", false, "If enabled, skips already imported tags")
root.Flags().BoolVar(&moduleMode, "module-mode", false, "If enabled, imports a module instead of a package") root.Flags().BoolVar(&moduleMode, "module-mode", false, "If enabled, imports a module instead of a package")
root.Flags().BoolVar(&tmpFsMode, "tmpfs-mode", false, "If enabled, packages are imported and patched but not pushed") root.Flags().StringVar(&tmpFsMode, "tmpfs-mode", "", "If set, packages are imported to path and patched but not pushed")
root.Flags().BoolVar(&noStorageDownload, "no-storage-download", false, "If enabled, blobs are always downloaded from upstream") root.Flags().BoolVar(&noStorageDownload, "no-storage-download", false, "If enabled, blobs are always downloaded from upstream")
root.Flags().BoolVar(&noStorageUpload, "no-storage-upload", false, "If enabled, blobs are not uploaded to blob storage") root.Flags().BoolVar(&noStorageUpload, "no-storage-upload", false, "If enabled, blobs are not uploaded to blob storage")

View File

@ -24,8 +24,8 @@ type ProcessData struct {
BlobStorage blob.Storage BlobStorage blob.Storage
NoDupMode bool NoDupMode bool
ModuleMode bool ModuleMode bool
TmpFsMode bool TmpFsMode string
NoStorageDownload bool NoStorageDownload bool
NoStorageUpload bool NoStorageUpload bool
FsCreator func() billy.Filesystem FsCreator func(branch string) billy.Filesystem
} }

View File

@ -87,18 +87,21 @@ func executePatchesRpm(pd *data.ProcessData, md *data.ModeData) {
log.Fatalf("could not create remote: %v", err) log.Fatalf("could not create remote: %v", err)
} }
err = repo.Fetch(&git.FetchOptions{ fetchOptions := &git.FetchOptions{
RemoteName: "origin", RemoteName: "origin",
RefSpecs: []config.RefSpec{refspec}, RefSpecs: []config.RefSpec{refspec},
Auth: pd.Authenticator, }
}) if !strings.HasPrefix(pd.UpstreamPrefix, "http") {
fetchOptions.Auth = pd.Authenticator
}
err = repo.Fetch(fetchOptions)
refName := plumbing.NewBranchReferenceName(md.PushBranch) refName := plumbing.NewBranchReferenceName(md.PushBranch)
log.Printf("set reference to ref: %s", refName) log.Printf("set reference to ref: %s", refName)
if err != nil { if err != nil {
// no patches active // no patches active
log.Println("info: patch Repo not found") log.Println("info: patch repo not found")
return return
} else { } else {
err = w.Checkout(&git.CheckoutOptions{ err = w.Checkout(&git.CheckoutOptions{

View File

@ -101,17 +101,6 @@ func ProcessRPM(pd *data.ProcessData) {
continue continue
} }
rpmFile := md.RpmFile
// create new Repo for final dist
repo, err := git.Init(memory.NewStorage(), pd.FsCreator())
if err != nil {
log.Fatalf("could not create new dist Repo: %v", err)
}
w, err := repo.Worktree()
if err != nil {
log.Fatalf("could not get dist Worktree: %v", err)
}
var matchString string var matchString string
if !tagImportRegex.MatchString(md.TagBranch) { if !tagImportRegex.MatchString(md.TagBranch) {
if pd.ModuleMode { if pd.ModuleMode {
@ -133,6 +122,17 @@ func ProcessRPM(pd *data.ProcessData) {
md.PushBranch = pd.BranchPrefix + strings.TrimPrefix(match[2], pd.ImportBranchPrefix) md.PushBranch = pd.BranchPrefix + strings.TrimPrefix(match[2], pd.ImportBranchPrefix)
newTag := "imports/" + pd.BranchPrefix + strings.TrimPrefix(match[1], "imports/"+pd.ImportBranchPrefix) newTag := "imports/" + pd.BranchPrefix + strings.TrimPrefix(match[1], "imports/"+pd.ImportBranchPrefix)
rpmFile := md.RpmFile
// create new Repo for final dist
repo, err := git.Init(memory.NewStorage(), pd.FsCreator(md.PushBranch))
if err != nil {
log.Fatalf("could not create new dist Repo: %v", err)
}
w, err := repo.Worktree()
if err != nil {
log.Fatalf("could not get dist Worktree: %v", err)
}
shouldContinue := true shouldContinue := true
for _, ignoredTag := range tagIgnoreList { for _, ignoredTag := range tagIgnoreList {
if ignoredTag == "refs/tags/"+newTag { if ignoredTag == "refs/tags/"+newTag {
@ -275,7 +275,7 @@ func ProcessRPM(pd *data.ProcessData) {
} }
} }
if pd.TmpFsMode { if pd.TmpFsMode != "" {
continue continue
} }