Skip to content
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

Merged
merged 3 commits into from
Mar 1, 2016

Conversation

cdrnet
Copy link
Member

@cdrnet cdrnet commented Mar 1, 2016

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.

… 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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member Author

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 ;)

@cdrnet cdrnet changed the title ProjectFile.touch to only modify the last write time without changing file content ProjectFile.save with forceTouch to only modify the last write time without changing content if unchanged Mar 1, 2016
@cdrnet
Copy link
Member Author

cdrnet commented Mar 1, 2016

Should I squash the commits together?

@cdrnet cdrnet changed the title ProjectFile.save with forceTouch to only modify the last write time without changing content if unchanged ProjectFile.save with forceTouch to only modify the last write time without content if unchanged Mar 1, 2016
@forki
Copy link
Member

forki commented Mar 1, 2016

Did you look at the build?

@forki
Copy link
Member

forki commented Mar 1, 2016

some tests timed out.

forki added a commit that referenced this pull request Mar 1, 2016
ProjectFile.save with forceTouch to only modify the last write time without content if unchanged
@forki forki merged commit c7594b3 into fsprojects:master Mar 1, 2016
@cdrnet
Copy link
Member Author

cdrnet commented Mar 1, 2016

Thanks!

@cdrnet cdrnet deleted the project-touch branch March 1, 2016 09:41
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.

3 participants