From bf0ab3216a4383b40468607657eb01c30428494c Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 27 Sep 2018 14:10:36 +0100 Subject: [PATCH 1/4] Leave VCS files when using clean after --- clean.go | 36 ++++++++++++++++++++++++++++++++++-- install.go | 10 +--------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/clean.go b/clean.go index eb3faa74..d68000b5 100644 --- a/clean.go +++ b/clean.go @@ -187,9 +187,8 @@ func cleanUntracked() error { } dir := filepath.Join(config.BuildDir, file.Name()) - if shouldUseGit(dir) { - if err = show(passToGit(dir, "clean", "-fx")); err != nil { + if err := show(passToGit(dir, "clean", "-fx")); err != nil { return err } } @@ -197,3 +196,36 @@ func cleanUntracked() error { return nil } + +func cleanAfter(bases []Base) { + fmt.Println("removing Untracked AUR files from cache...") + + 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.Printf("error resetting %s: %s", base.String(), stderr) + } + + show(passToGit(dir, "clean", "-fx")) + } else { + fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(bases), cyan(dir)) + if err := os.RemoveAll(dir); err != nil { + fmt.Println(err) + } + } + } +} + +func cleanBuilds(bases []Base) { + for i, base := range bases { + dir := filepath.Join(config.BuildDir, base.Pkgbase()) + fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(bases), cyan(dir)) + if err := os.RemoveAll(dir); err != nil { + fmt.Println(err) + } + } +} diff --git a/install.go b/install.go index 623b0ecb..06d54b82 100644 --- a/install.go +++ b/install.go @@ -341,7 +341,7 @@ func install(parser *arguments) error { } if config.CleanAfter { - cleanBuilds(do.Aur) + cleanAfter(do.Aur) } return nil @@ -680,14 +680,6 @@ func editDiffNumberMenu(bases []Base, installed stringSet, diff bool) ([]Base, e return toEdit, nil } -func cleanBuilds(bases []Base) { - for i, base := range bases { - dir := filepath.Join(config.BuildDir, base.Pkgbase()) - fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(bases), cyan(dir)) - os.RemoveAll(dir) - } -} - func showPkgbuildDiffs(bases []Base, cloned stringSet) error { for _, base := range bases { pkg := base.Pkgbase() From 98e6caefef3ef53db45495b17d5591140a8041d0 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 27 Sep 2018 14:21:49 +0100 Subject: [PATCH 2/4] Fix dangling src/ directory Yay first calls 'makepkg --nobuild -fC' to update the pkver. Later on we call 'makepkg -cf --noectract --noprepare --holdver' to actually build the package. Inbetween these two calls we keep the already extracted sources to save time on the reextract and duplicated call to prepare (pkgbuilds should not require user input but things such as linux-ck do and calling prepare twice will actually cause them to promt twice) We also have two checks. First we see if the package is already installed and up to date (--needed) and secondly we check if the package is already built. If any of these conditions are met we skip building the package. This leaves a dangling src/ directory as 'makepkg -c' was never ran. Now if these conditions are met tell makepkg to cleanup and exit. --- install.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.go b/install.go index 06d54b82..9b95e53a 100644 --- a/install.go +++ b/install.go @@ -954,12 +954,14 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc } if installed { + show(passToMakepkg(dir, "-c", "--nobuild", "--noextract", "--ignorearch")) fmt.Println(cyan(pkg+"-"+version) + bold(" is up to date -- skipping")) continue } } if built { + show(passToMakepkg(dir, "-c", "--nobuild", "--noextract", "--ignorearch")) fmt.Println(bold(yellow(arrow)), cyan(pkg+"-"+version)+bold(" already made -- skipping build")) } else { From 42cba531656fec8522ee04fc3302314e6a34c60a Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 27 Sep 2018 16:08:00 +0100 Subject: [PATCH 3/4] Update doc for --afterclean and fix typo --- doc/yay.8 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/yay.8 b/doc/yay.8 index 5b8bce0c..15aab6e1 100644 --- a/doc/yay.8 +++ b/doc/yay.8 @@ -134,7 +134,7 @@ Only show titles when printing news. .B \-f, \-\-force Force download for packages that already exist in the current directory. This is to ensure directories are not accidentally overwritten. This option is not -needed for git based downloads as \fBgit pull\fR already has saftey mechanisms. +needed for git based downloads as \fBgit pull\fR already has safety mechanisms. .SH PERMANENT CONFIGURATION SETTINGS .TP @@ -362,6 +362,12 @@ previously installed packages still apply. .B \-\-afterclean Remove package sources after successful Install. +For packages downloaded through git, untracked files are removed with the +exception of directories. This allows VCS packages to ealily pull an update +instead of having to re clone the entire repo. + +For packages downloaded via tarball, The entire directory is deleted. + .TP .B \-\-noafterclean Do not remove package sources after successful Install. From 4cc57dd9703e0cdfe9330cee65b1086bd81911f9 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 27 Sep 2018 16:12:43 +0100 Subject: [PATCH 4/4] Rename afterclean to cleanafter This makes more sense and falls in line with the structs value which has always been cleanafter. afterclean is still useable for compatibility but is undocumented. --- cmd.go | 4 ++-- completions/bash | 2 +- completions/fish | 4 ++-- completions/zsh | 4 ++-- doc/yay.8 | 4 ++-- parser.go | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd.go b/cmd.go index 16249910..168a901d 100644 --- a/cmd.go +++ b/cmd.go @@ -79,8 +79,8 @@ Permanent configuration options: --removemake Remove makedepends after install --noremovemake Don't remove makedepends after install - --afterclean Remove package sources after successful install - --noafterclean Do not remove package sources after successful build + --cleanafter Remove package sources after successful install + --nocleanafter Do not remove package sources after successful build --bottomup Shows AUR's packages first and then repository's --topdown Shows repository's packages first and then AUR's diff --git a/completions/bash b/completions/bash index 83ef41b7..903e1fe7 100644 --- a/completions/bash +++ b/completions/bash @@ -66,7 +66,7 @@ _yay() { makepkg pacman tar git gpg gpgflags config requestsplitn sudoloop nosudoloop redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild sortby answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff - noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu + noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu cleanafter nocleanafter nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf nomakepkgconf askremovemake removemake noremovemake completioninterval aururl' diff --git a/completions/fish b/completions/fish index c51b3cf0..eea19f84 100644 --- a/completions/fish +++ b/completions/fish @@ -65,8 +65,8 @@ 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 afterclean -d 'Clean package sources after successful build' -f -complete -c $progname -n "not $noopt" -l noafterclean -d 'Disable package sources cleaning' -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 complete -c $progname -n "not $noopt" -l notimeupdate -d 'Check only package version change' -f diff --git a/completions/zsh b/completions/zsh index cb76a2f8..ae4e65b9 100644 --- a/completions/zsh +++ b/completions/zsh @@ -80,8 +80,8 @@ _pacman_opts_common=( '--topdown[Show repository packages first]' '--devel[Check -git/-svn/-hg development version]' '--nodevel[Disable development version checking]' - '--afterclean[Clean package sources after successful build]' - '--noafterclean[Disable package sources cleaning after successful build]' + '--cleanafter[Clean package sources after successful build]' + '--nocleanafter[Disable package sources cleaning after successful build]' '--timeupdate[Check packages modification date and version]' '--notimeupdate[Check only package version change]' '--redownload[Always download pkgbuilds of targets]' diff --git a/doc/yay.8 b/doc/yay.8 index 15aab6e1..699ecce8 100644 --- a/doc/yay.8 +++ b/doc/yay.8 @@ -359,7 +359,7 @@ Download and update PKGBUILDs using tarballs. The above conditions about previously installed packages still apply. .TP -.B \-\-afterclean +.B \-\-cleanafter Remove package sources after successful Install. For packages downloaded through git, untracked files are removed with the @@ -369,7 +369,7 @@ instead of having to re clone the entire repo. For packages downloaded via tarball, The entire directory is deleted. .TP -.B \-\-noafterclean +.B \-\-nocleanafter Do not remove package sources after successful Install. .TP diff --git a/parser.go b/parser.go index 7f175572..1c05aab7 100644 --- a/parser.go +++ b/parser.go @@ -419,8 +419,8 @@ func isArg(arg string) bool { //yay options case "aururl": case "save": - case "afterclean": - case "noafterclean": + case "afterclean", "cleanafter": + case "noafterclean", "nocleanafter": case "devel": case "nodevel": case "timeupdate": @@ -501,9 +501,9 @@ func handleConfig(option, value string) bool { config.AURURL = value case "save": shouldSaveConfig = true - case "afterclean": + case "afterclean", "cleanafter": config.CleanAfter = true - case "noafterclean": + case "noafterclean", "nocleanafter": config.CleanAfter = false case "devel": config.Devel = true