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

Projects
None yet
3 participants
@cdrnet
Member

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.

ProjectFile.touch to only modify the last write time without changing…
… file content

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, the only effect of --touch-affected-refs will be a
modified last-write time file attribute.
Show outdated Hide outdated src/Paket.Core/ProjectFile.fs
@@ -941,6 +941,9 @@ module ProjectFile =
project.ProjectNode.AppendChild analyzersNode |> ignore
)
let touch (project:ProjectFile) =
if File.Exists(project.FileName) then

This comment has been minimized.

@mexx

mexx Mar 1, 2016

Member

It changes the logic previously present.
When the file wasn't present, it was created by the save true project call.
Please adjust accordingly.

@mexx

mexx Mar 1, 2016

Member

It changes the logic previously present.
When the file wasn't present, it was created by the save true project call.
Please adjust accordingly.

This comment has been minimized.

@cdrnet

cdrnet Mar 1, 2016

Member

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.

@cdrnet

cdrnet Mar 1, 2016

Member

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.

This comment has been minimized.

@mexx

mexx Mar 1, 2016

Member

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.

@mexx

mexx Mar 1, 2016

Member

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.

This comment has been minimized.

@cdrnet

cdrnet Mar 1, 2016

Member

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?

@cdrnet

cdrnet Mar 1, 2016

Member

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?

This comment has been minimized.

@mexx

mexx Mar 1, 2016

Member

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.

@mexx

mexx Mar 1, 2016

Member

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.

This comment has been minimized.

@cdrnet

cdrnet Mar 1, 2016

Member

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)
@cdrnet

cdrnet Mar 1, 2016

Member

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)

This comment has been minimized.

@cdrnet

cdrnet Mar 1, 2016

Member

Seems we've come to the same conclusion concurrently ;)

@cdrnet

cdrnet Mar 1, 2016

Member

Seems we've come to the same conclusion concurrently ;)

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

@cdrnet

This comment has been minimized.

Show comment
Hide comment
@cdrnet

cdrnet Mar 1, 2016

Member

Should I squash the commits together?

Member

cdrnet commented Mar 1, 2016

Should I squash the commits together?

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

@forki

This comment has been minimized.

Show comment
Hide comment
@forki

forki Mar 1, 2016

Member

Did you look at the build?

Member

forki commented Mar 1, 2016

Did you look at the build?

@forki

This comment has been minimized.

Show comment
Hide comment
@forki

forki Mar 1, 2016

Member

some tests timed out.

Member

forki commented Mar 1, 2016

some tests timed out.

forki added a commit that referenced this pull request Mar 1, 2016

Merge pull request #1493 from cdrnet/project-touch
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

0 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@cdrnet

This comment has been minimized.

Show comment
Hide comment
@cdrnet

cdrnet Mar 1, 2016

Member

Thanks!

Member

cdrnet commented Mar 1, 2016

Thanks!

@cdrnet cdrnet deleted the cdrnet:project-touch branch Mar 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment