mage icon indicating copy to clipboard operation
mage copied to clipboard

It is difficult to get make-like behaviour with target.Path

Open bdalton opened this issue 8 years ago • 5 comments

There are two cases in make where a rule is executed:

  1. the target does not exist.
  2. the target is older than one of the sources.

target.Path(dst, sources...) returns true, nil on (2), but returns false, err on (1). That leads me to think that maybe I could do something like this:

outOfDate, err := target.Path(dst, source1, source2)
if err != nil && !os.IsNotExist(err) {
   return err
}
if outOfDate || os.IsNotExist(err) {
   ... action ...
}

Unfortunately, if any of the sources doesn't exist, I will also get an os.IsNotExist() also returning true so I can't distinguish between the target not existing and one of the sources existing.

bdalton avatar Jul 16 '18 16:07 bdalton

Hm... so this sounds like a bug. The destination not existing should just return true, nil. not existing is definitely out of date. Only the source not existing should be an error. We should get that fixed.

Also, I see that the docs on these functions are not sufficient, since they don't explain what happens with not existing.

Thanks for the report. I'll try to get to this soon (or you're welcome to submit a PR).

natefinch avatar Jul 16 '18 17:07 natefinch

Sure, I'll submit a PR later today

bdalton avatar Jul 18 '18 15:07 bdalton

PR submitted

bdalton avatar Jul 18 '18 17:07 bdalton

Thank you!

natefinch avatar Jul 18 '18 20:07 natefinch

fixed by 131. If there's a different behavior you'd like, we can add it to another function, perhaps.

natefinch avatar Aug 24 '18 18:08 natefinch