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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Paket.Core/FindReferences.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let TouchReferencesOfPackages packages environment = trial {
|> List.distinctBy (fun project-> project.FileName)
|> List.iter (fun project ->
verbosefn "Touching project %s" project.FileName
ProjectFile.save true project)
ProjectFile.touch project)
}

let ShowReferencesFor packages environment = trial {
Expand Down
7 changes: 6 additions & 1 deletion src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;)

File.SetLastWriteTimeUtc(project.FileName, DateTime.UtcNow)

let save forceTouch project =
if forceTouch then
Expand Down Expand Up @@ -1305,7 +1308,9 @@ type ProjectFile with
member this.RemovePaketNodes () = ProjectFile.removePaketNodes this

member this.UpdateReferences (completeModel, usedPackages, hard) = ProjectFile.updateReferences completeModel usedPackages hard this


member this.Touch () = ProjectFile.touch this

member this.Save(forceTouch) = ProjectFile.save forceTouch this

member this.GetPaketFileItems () = ProjectFile.getPaketFileItems this
Expand Down