-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProjectFile.save with forceTouch to only modify the last write time without content if unchanged #1493
Conversation
… file content This is a follow up to fsprojects#1485 which introduced the optional --touch-affected-refs parameter on restore. In the original implementation this caused the project file to be saved forcefully, which could in some cases cause the file content to change slightly (e.g. minor xml formatting). With this change, the only effect of --touch-affected-refs will be a modified last-write time file attribute.
@@ -941,6 +941,9 @@ module ProjectFile = | |||
project.ProjectNode.AppendChild analyzersNode |> ignore | |||
) | |||
|
|||
let touch (project:ProjectFile) = | |||
if File.Exists(project.FileName) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It changes the logic previously present.
When the file wasn't present, it was created by the save true project
call.
Please adjust accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not change any behavior as before the touching was only exposed indirectly through routines where the file was known to be present.
But I agree, touch
is typically expected to create the file if not present. Since it is exposed directly now, we better adapt it to follow that expectation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You maybe right about the way how it was ever accessed, but my comment was based on the how the logic is written in the save function and how it changed in the touch. I mean touch
was intended to be equivalent to save true
, right? No matter in which context is ever called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - touch is not intended to change the file content, only to make the file appear as if it had changed. Just like the touch tool on unix. The primary use case is to help msbuild incremental build detect it needs to rebuild a project.
Maybe it was a mistake to expose it as member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little bit incorrect in my wording, touch
was intended to replace the save true
call.
But you're right, why should it be there in first place?
The project file should know the own state, whether it's changed or not, right? So save true
could actually utilize this knowledge to decide whether to simply change the last access date or write out the contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought - maybe it would make more sense to slightly change the behavior of save
instead of adding touch, along the lines of:
let save forceTouch project =
if Utils.normalizeXml project.Document <> project.OriginalText then
verbosefn "Project %s changed" project.FileName
project.Document.Save(project.FileName)
elif forceTouch && File.Exists(project.FileName) then
File.SetLastWriteTimeUtc(project.FileName, DateTime.UtcNow)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we've come to the same conclusion concurrently ;)
Should I squash the commits together? |
…ad of content if unchanged
Did you look at the build? |
some tests timed out. |
ProjectFile.save with forceTouch to only modify the last write time without content if unchanged
Thanks! |
This is a follow up to #1485 which introduced the optional --touch-affected-refs
parameter on restore. In the original implementation this caused the
project file to be saved forcefully, which could in some cases cause the
file content to change slightly (e.g. minor xml formatting).
With this change, save with forceTouch=true only saves the content if it has actually changed. Otherwise it only sets the last-write-time to now.