Better detect last run script in mock chroot

Before when running one of the following targets it could be that there were multiple run files in `/var/lib/mock/$(MOCK_CHROOT)/root/var/tmp`.

```
edit-last-failing-script              - Opens the last failing or running script from mock in your editor
                                        of choice for you to edit it and later re-run it in mock with:
                                        "make mockbuild-rerun-last-script-...".
mockbuild-rerun-last-script           - Re-runs the last failing or running script of your release/mock mockbuild.
```

The function to edit the last one that was run sometimes picked the wrong file. Now we sort the files in there aforementioned directory before editing or running it again.
This commit is contained in:
Konrad Kleine 2024-11-20 11:45:11 +01:00
parent 1acc1f3d64
commit 28f33f948e

View file

@ -72,19 +72,26 @@ mockbuild-snapshot: srpm-snapshot get-srpm-snapshot
######### Edit-last-failing-script ######### Edit-last-failing-script
.PHONY: get-last-run-script
## Get the file that was last modified in /var/tmp/ within the chroot.
get-last-run-script:
$(eval last_run_script:=/var/tmp/$(shell ls -t1 /var/lib/mock/$(MOCK_CHROOT)/root/var/tmp | head -n1))
$(info last_run_script=$(last_run_script))
@echo > /dev/null
.PHONY: edit-last-failing-script .PHONY: edit-last-failing-script
## Opens the last failing or running script from mock in your editor ## Opens the last failing or running script from mock in your editor
## of choice for you to edit it and later re-run it in mock with: ## of choice for you to edit it and later re-run it in mock with:
## "make mockbuild-rerun-last-script-...". ## "make mockbuild-rerun-last-script".
edit-last-failing-script: edit-last-failing-script: get-last-run-script
$$EDITOR /var/lib/mock/$(MOCK_CHROOT)/root/var/tmp/rpm-tmp.* $$EDITOR /var/lib/mock/$(MOCK_CHROOT)/root$(last_run_script)
######### Re-run the last failing script from mock ######### Re-run the last failing script from mock
.PHONY: mockbuild-rerun-last-script .PHONY: mockbuild-rerun-last-script
## Re-runs the last failing or running script of your release/mock mockbuild. ## Re-runs the last failing or running script of your release/mock mockbuild.
mockbuild-rerun-last-script: mockbuild-rerun-last-script: get-last-run-script
mock --root=$(MOCK_CHROOT) --shell 'sh -e /var/tmp/rpm-tmp.*' mock --root=$(MOCK_CHROOT) --shell 'sh -e $(last_run_script)'
.PHONY: help .PHONY: help
# Based on https://gist.github.com/rcmachado/af3db315e31383502660 # Based on https://gist.github.com/rcmachado/af3db315e31383502660