Skip to content

Commit

Permalink
Remove tar support
Browse files Browse the repository at this point in the history
tar is slower and harder to diff. I doubt any one still uses it intentially.

There's a chance some people have not cleared their cache in two years
and still have tar based packages around. But forcing them to clear
their cache is not a big deal at all.
  • Loading branch information
Morganamilo committed Nov 4, 2019
1 parent bbc7cbb commit 9ef6d51
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 182 deletions.
27 changes: 9 additions & 18 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ func cleanUntracked() error {
}

dir := filepath.Join(config.BuildDir, file.Name())
if shouldUseGit(dir) {
if err := show(passToGit(dir, "clean", "-fx")); err != nil {
return err
}
if err := show(passToGit(dir, "clean", "-fx")); err != nil {
return err
}
}

Expand All @@ -208,21 +206,14 @@ func cleanAfter(bases []Base) {
for i, base := range bases {
dir := filepath.Join(config.BuildDir, base.Pkgbase())

if shouldUseGit(dir) {
fmt.Printf(bold(cyan("::")+" Cleaning (%d/%d): %s\n"), i+1, len(bases), cyan(dir))
_, stderr, err := capture(passToGit(dir, "reset", "--hard", "HEAD"))
if err != nil {
fmt.Fprintf(os.Stderr, "error resetting %s: %s", base.String(), stderr)
}
fmt.Printf(bold(cyan("::")+" Cleaning (%d/%d): %s\n"), i+1, len(bases), cyan(dir))
_, stderr, err := capture(passToGit(dir, "reset", "--hard", "HEAD"))
if err != nil {
fmt.Fprintf(os.Stderr, "error resetting %s: %s", base.String(), stderr)
}

if err := show(passToGit(dir, "clean", "-fx")); err != nil {
fmt.Fprintln(os.Stderr, err)
}
} else {
fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(bases), cyan(dir))
if err := os.RemoveAll(dir); err != nil {
fmt.Fprintln(os.Stderr, err)
}
if err := show(passToGit(dir, "clean", "-fx")); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Permanent configuration options:
--makepkg <file> makepkg command to use
--mflags <flags> Pass arguments to makepkg
--pacman <file> pacman command to use
--tar <file> bsdtar command to use
--git <file> git command to use
--gitflags <flags> Pass arguments to git
--gpg <file> gpg command to use
Expand Down Expand Up @@ -91,8 +90,6 @@ Permanent configuration options:
--devel Check development packages during sysupgrade
--nodevel Do not check development packages
--gitclone Use git clone for PKGBUILD retrieval
--nogitclone Never use git clone for PKGBUILD retrieval
--rebuild Always build target packages
--rebuildall Always build all AUR packages
--norebuild Skip package build if in cache and up to date
Expand Down Expand Up @@ -131,7 +128,7 @@ yay specific options:
--gendb Generates development package DB used for updating
getpkgbuild specific options:
-f --force Force download for existing tar packages
-f --force Force download for existing ABS packages
If no arguments are provided 'yay -Syu' will be performed
If no operation is provided -Y will be assumed`)
Expand Down
4 changes: 1 addition & 3 deletions completions/fish
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ complete -c $progname -n "$show" -s w -l news -d 'Print arch news' -f
complete -c $progname -n "$show" -s q -l quiet -d 'Do not print news description' -f

# Getpkgbuild options
complete -c $progname -n "$getpkgbuild" -s f -l force -d 'Force download for existing tar packages' -f
complete -c $progname -n "$getpkgbuild" -s f -l force -d 'Force download for existing ABS packages' -f
complete -c $progname -n "$getpkgbuild" -xa "$listall"

# Premenent configuration settings
Expand Down Expand Up @@ -217,8 +217,6 @@ complete -c $progname -n "not $noopt" -l topdown -d 'Shows repository packages f
complete -c $progname -n "not $noopt" -l bottomup -d 'Shows aur packages first and then repository' -f
complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg development version' -f
complete -c $progname -n "not $noopt" -l nodevel -d 'Disable development version checking' -f
complete -c $progname -n "not $noopt" -l gitclone -d 'Use git to download and update PKGBUILDs' -f
complete -c $progname -n "not $noopt" -l nogitclone -d 'Download and update PKGBUILDs using tarballs' -f
complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f
complete -c $progname -n "not $noopt" -l nocleanafter -d 'Disable package sources cleaning' -f
complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f
Expand Down
2 changes: 0 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type Configuration struct {
NoConfirm bool `json:"-"`
Devel bool `json:"devel"`
CleanAfter bool `json:"cleanAfter"`
GitClone bool `json:"gitclone"`
Provides bool `json:"provides"`
PGPFetch bool `json:"pgpfetch"`
UpgradeMenu bool `json:"upgrademenu"`
Expand Down Expand Up @@ -180,7 +179,6 @@ func defaultSettings() *Configuration {
AnswerEdit: "",
AnswerUpgrade: "",
RemoveMake: "ask",
GitClone: true,
Provides: true,
UpgradeMenu: true,
CleanMenu: true,
Expand Down
34 changes: 9 additions & 25 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Perform yay specific print operations.

.TP
.B \-G, \-\-getpkgbuild
Downloads PKGBUILD from ABS or AUR. ABS pkgbuilds are always downloaded using
tarballs and taken from trunk. The ABS can only be used for Arch Linux repositories
Downloads PKGBUILD from ABS or AUR. The ABS can only be used for Arch Linux
repositories

.RE
If no arguments are provided 'yay \-Syu' will be performed.
Expand All @@ -47,9 +47,8 @@ These operations are extended to support both AUR and repo packages.
.TP
.B \-Sc
Yay will also clean cached AUR package and any untracked Files in the
cache. Untracked files cleaning only works for packages downloaded
using gitclone. Cleaning untracked files will wipe any downloaded
sources or built packages but will keep already downloaded vcs sources.
cache. Cleaning untracked files will wipe any downloaded sources or
built packages but will keep already downloaded vcs sources.

.TP
.B \-R
Expand Down Expand Up @@ -132,9 +131,8 @@ Only show titles when printing news.
.SH GETPKGBUILD OPTIONS (APPLY TO \-G AND \-\-GETPKGBUILD)
.TP
.B \-f, \-\-force
Force download for packages that already exist in the current directory. This
ensures directories are not accidentally overwritten. This option is not needed
for git based downloads as \fBgit pull\fR already has safety mechanisms.
Force download for ABS packages that already exist in the current directory. This
ensures directories are not accidentally overwritten.

.SH PERMANENT CONFIGURATION SETTINGS
.TP
Expand Down Expand Up @@ -355,28 +353,14 @@ a list of packages into yay (see \fBexamples\fR).
.B \-\-nodevel
Do not check for development packages updates during sysupgrade.

.TP
.B \-\-gitclone
Use git to download and update PKGBUILDs. PKGBUILDs previously downloaded
using tarball will continue to use tarballs until the package is clean
built. Similarly, PKGBUILDs managed with git will continue to use git until
the package is clean built..

.TP
.B \-\-nogitclone
Download and update PKGBUILDs using tarballs. The above conditions about
previously installed packages still apply.

.TP
.B \-\-cleanafter
Remove package sources after successful Install.
Remove untracked files after installation.

For packages downloaded through git, untracked files are removed with the
exception of directories. This allows VCS packages to easily pull an update
Untracked files are removed with the exception of directories.
This allows VCS packages to easily pull an update
instead of having to re clone the entire repo.

For packages downloaded via tarball, the entire directory is deleted.

.TP
.B \-\-nocleanafter
Do not remove package sources after successful Install.
Expand Down
66 changes: 1 addition & 65 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
Expand All @@ -16,40 +14,6 @@ import (

const gitDiffRefName = "AUR_SEEN"

// Decide what download method to use:
// Use the config option when the destination does not already exits
// If .git exists in the destination use git
// Otherwise use a tarrball
func shouldUseGit(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return config.GitClone
}

_, err = os.Stat(filepath.Join(path, ".git"))
return err == nil || os.IsExist(err)
}

func downloadFile(path string, url string) (err error) {
// Create the file
out, err := os.Create(path)
if err != nil {
return err
}
defer out.Close()

// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Writer the body to file
_, err = io.Copy(out, resp.Body)
return err
}

// Update the YAY_DIFF_REVIEW ref to HEAD. We use this ref to determine which diff were
// reviewed by the user
func gitUpdateSeenRef(path string, name string) error {
Expand Down Expand Up @@ -172,31 +136,6 @@ func gitMerge(path string, name string) error {
return nil
}

// DownloadAndUnpack downloads url tgz and extracts to path.
func downloadAndUnpack(url string, path string) error {
err := os.MkdirAll(path, 0755)
if err != nil {
return err
}

fileName := filepath.Base(url)

tarLocation := filepath.Join(path, fileName)
defer os.Remove(tarLocation)

err = downloadFile(tarLocation, url)
if err != nil {
return err
}

_, stderr, err := capture(exec.Command(config.TarBin, "-xf", tarLocation, "-C", path))
if err != nil {
return fmt.Errorf("%s", stderr)
}

return nil
}

func getPkgbuilds(pkgs []string) error {
missing := false
wd, err := os.Getwd()
Expand Down Expand Up @@ -239,14 +178,11 @@ func getPkgbuilds(pkgs []string) error {
case err != nil && !os.IsNotExist(err):
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
continue
case os.IsNotExist(err), cmdArgs.existsArg("f", "force"), shouldUseGit(filepath.Join(wd, name)):
default:
if err = os.RemoveAll(filepath.Join(wd, name)); err != nil {
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
continue
}
default:
fmt.Printf("%s %s %s\n", yellow(smallArrow), cyan(name), "already downloaded -- use -f to overwrite")
continue
}

bases = append(bases, base)
Expand Down
93 changes: 34 additions & 59 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,9 @@ func updatePkgbuildSeenRef(bases []Base, cloned stringset.StringSet) error {
var errMulti multierror.MultiError
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
if shouldUseGit(dir) {
err := gitUpdateSeenRef(config.BuildDir, pkg)
if err != nil {
errMulti.Add(err)
}
err := gitUpdateSeenRef(config.BuildDir, pkg)
if err != nil {
errMulti.Add(err)
}
}
return errMulti.Return()
Expand All @@ -736,46 +733,34 @@ func showPkgbuildDiffs(bases []Base, cloned stringset.StringSet) error {
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
if shouldUseGit(dir) {
start, err := getLastSeenHash(config.BuildDir, pkg)
start, err := getLastSeenHash(config.BuildDir, pkg)
if err != nil {
errMulti.Add(err)
continue
}

if cloned.Get(pkg) {
start = gitEmptyTree
} else {
hasDiff, err := gitHasDiff(config.BuildDir, pkg)
if err != nil {
errMulti.Add(err)
continue
}

if cloned.Get(pkg) {
start = gitEmptyTree
} else {
hasDiff, err := gitHasDiff(config.BuildDir, pkg)
if err != nil {
errMulti.Add(err)
continue
}

if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(base.String()), bold("No changes -- skipping"))
continue
}
if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(base.String()), bold("No changes -- skipping"))
continue
}
}

args := []string{"diff", start + "..HEAD@{upstream}", "--src-prefix", dir + "/", "--dst-prefix", dir + "/", "--", ".", ":(exclude).SRCINFO"}
if useColor {
args = append(args, "--color=always")
} else {
args = append(args, "--color=never")
}
_ = show(passToGit(dir, args...))
args := []string{"diff", start + "..HEAD@{upstream}", "--src-prefix", dir + "/", "--dst-prefix", dir + "/", "--", ".", ":(exclude).SRCINFO"}
if useColor {
args = append(args, "--color=always")
} else {
args := []string{"diff"}
if useColor {
args = append(args, "--color=always")
} else {
args = append(args, "--color=never")
}
args = append(args, "--no-index", "/var/empty", dir)
// git always returns 1. why? I have no idea
_ = show(passToGit(dir, args...))
args = append(args, "--color=never")
}
_ = show(passToGit(dir, args...))
}

return errMulti.Return()
Expand Down Expand Up @@ -861,11 +846,9 @@ func pkgbuildsToSkip(bases []Base, targets stringset.StringSet) stringset.String

func mergePkgbuilds(bases []Base) error {
for _, base := range bases {
if shouldUseGit(filepath.Join(config.BuildDir, base.Pkgbase())) {
err := gitMerge(config.BuildDir, base.Pkgbase())
if err != nil {
return err
}
err := gitMerge(config.BuildDir, base.Pkgbase())
if err != nil {
return err
}
}

Expand All @@ -892,23 +875,15 @@ func downloadPkgbuilds(bases []Base, toSkip stringset.StringSet, buildDir string
return
}

if shouldUseGit(filepath.Join(config.BuildDir, pkg)) {
clone, err := gitDownload(config.AURURL+"/"+pkg+".git", buildDir, pkg)
if err != nil {
errs.Add(err)
return
}
if clone {
mux.Lock()
cloned.Set(pkg)
mux.Unlock()
}
} else {
err := downloadAndUnpack(config.AURURL+base.URLPath(), buildDir)
if err != nil {
errs.Add(err)
return
}
clone, err := gitDownload(config.AURURL+"/"+pkg+".git", buildDir, pkg)
if err != nil {
errs.Add(err)
return
}
if clone {
mux.Lock()
cloned.Set(pkg)
mux.Unlock()
}

mux.Lock()
Expand Down
Loading

0 comments on commit 9ef6d51

Please sign in to comment.