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/osfs"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"io/ioutil"
"log"
"os"
"os/user"
@ -38,7 +37,7 @@ var (
singleTag string
noDupMode bool
moduleMode bool
tmpFsMode bool
tmpFsMode string
noStorageDownload bool
noStorageUpload bool
)
@ -96,20 +95,17 @@ func mn(_ *cobra.Command, _ []string) {
log.Fatalf("could not get git authenticator: %v", err)
}
fsCreator := func() billy.Filesystem {
fsCreator := func(branch string) billy.Filesystem {
return memfs.New()
}
if tmpFsMode {
tmpBaseDir, err := ioutil.TempDir(os.TempDir(), "srpmproc-*")
if err != nil {
log.Fatalf("could not create temp dir: %v", err)
}
log.Printf("using temp dir: %s", tmpBaseDir)
fsCreator = func() billy.Filesystem {
tmpDir, err := ioutil.TempDir(tmpBaseDir, "*")
if tmpFsMode != "" {
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 {
log.Fatalf("could not create temp dir: %v", err)
log.Fatalf("could not create tmpfs dir: %v", err)
}
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().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(&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(&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
NoDupMode bool
ModuleMode bool
TmpFsMode bool
TmpFsMode string
NoStorageDownload 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)
}
err = repo.Fetch(&git.FetchOptions{
fetchOptions := &git.FetchOptions{
RemoteName: "origin",
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)
log.Printf("set reference to ref: %s", refName)
if err != nil {
// no patches active
log.Println("info: patch Repo not found")
log.Println("info: patch repo not found")
return
} else {
err = w.Checkout(&git.CheckoutOptions{

View File

@ -101,17 +101,6 @@ func ProcessRPM(pd *data.ProcessData) {
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
if !tagImportRegex.MatchString(md.TagBranch) {
if pd.ModuleMode {
@ -133,6 +122,17 @@ func ProcessRPM(pd *data.ProcessData) {
md.PushBranch = pd.BranchPrefix + strings.TrimPrefix(match[2], 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
for _, ignoredTag := range tagIgnoreList {
if ignoredTag == "refs/tags/"+newTag {
@ -275,7 +275,7 @@ func ProcessRPM(pd *data.ProcessData) {
}
}
if pd.TmpFsMode {
if pd.TmpFsMode != "" {
continue
}