pkg/api: fix Rebuild always write to output files

On the first Rebuild, the oldHashes is empty, so the condition that
checking between old and new hash will always false which makes
the output files always written.

This changes fix this issue by moving the content comparison only if no
old hash found.