Skip to content

Fix generates problems.#2317

Closed
trulede wants to merge 2 commits intogo-task:mainfrom
trulede:generate-fixes
Closed

Fix generates problems.#2317
trulede wants to merge 2 commits intogo-task:mainfrom
trulede:generate-fixes

Conversation

@trulede
Copy link
Copy Markdown
Contributor

@trulede trulede commented Jul 5, 2025

Fixes some problems with 'generates'.

1. Generates with timestamp method does not generate deleted files

Previously generated files, then deleted, are not regenerated when Task is subsequently run.

Task does not actually check the generates items exist, rather, it cunningly 'globs" each generates item and only notices those files which exist, and the timestamp file itself. That means, if you delete a file, task will not notice and because the timestamp file, created when the source last changed, was considered for the check ... another cunning move ... it will appear that the task is up-to-date.

Solution is to adopt the glob mechanism from checksum. If a generate item is globbed and returns no files, or a NotExist error, then return indicating that the Task should run.

2. Generates (and sources) items with a space in filename will be expanded correctly.

Curiously, this problem is often masked by the first problem. In any case, it seems that a fix from long ago has been lost. The fix is introduced again, at a slightly different location (i.e. the glob() function).

Original fix here.

fixes #2314
fixes #1506
fixes #1230

@andreynering andreynering self-requested a review July 5, 2025 16:45
@trulede
Copy link
Copy Markdown
Contributor Author

trulede commented Jul 6, 2025

It might be worthwhile adding a few more test cases.

Copy link
Copy Markdown
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @trulede,

The fixes in the PR are now already present in the codebase, so I'm closing this one.

If I'm missing anything, please let me know.


func glob(dir string, g string) ([]string, error) {
g = filepathext.SmartJoin(dir, g)
g = strings.ReplaceAll(g, " ", `\ `)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually already being applied, but let me know if I'm missing anything.

ExpandFields called below already calls escape which converts " " into "\\ " as you're doing here.

}
generates, err := Globs(t.Dir, t.Generates)
if err != nil {
generates := []string{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were made on #2716, which also adds some good tests to this behavior. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A timestamp method is expected when using sources and generates method: timestamp does not run when generates: path is missing

2 participants