Now that dep ensure can be used to update the manifest (via dep ensure -add), we need to make sure that the written manifest is actually still valid TOML.
This issue is for resolving this FIXME in *ensureCommand.runAdd.
I'd prefer if Gopkg.toml was backed up before writing out the additional constraints for easy recovery. (Similar to what dep.*SafeWrite.Write does).
@sdboyer Should this be implemented in dep.SafeWriter instead?
@ibrasho @sdboyer Can I tackle this as my PR to dep?
@RaviTezu absolutely!
I'd prefer if Gopkg.toml was backed up before writing out the additional constraints for easy recovery.
i think we can avoid the need for this by generating the appended []byte slice in memory, then reparsing it and validating it, and only _then_ actually writing out to disk.
Should this be implemented in dep.SafeWriter instead?
it definitely should; i only did it where i did initially as a hack.
Hi @ibrasho
Please correct me If I am wrong: I think, if the appended manifest is not valid, call to MarshalTOML here on appender will return an error?
If Yes, I just to verify the final manifest is a valid TOML and we are good?
Now, what if the the final manifest is not a valid TOML? What would be the best way to put back the previous manifest?
I am thinking, of writing something similar to dep.*SafeWrite.Write which will only takes care reverting the manifest file to previous state, if something is wrong?
I am sorry, if I am missing something.
Now, what if the the final manifest is not a valid TOML? What would be the best way to put back the previous manifest?
the key here is that validation should occur on an in-memory []byte that contains all the TOML data, _before_ writing it to disk. we only write if it passes validation.
Most helpful comment
@ibrasho @sdboyer Can I tackle this as my PR to dep?