Don't change BOM for existing project files - fixes #2271 - #2575
Conversation
|
|
||
|
|
||
| let save forceTouch project = | ||
| let hasUtf8Bom fileName = |
There was a problem hiding this comment.
Should this go in another place? I kept it as a local function because it's only used here.
| if File.Exists fileName then | ||
| use fs = new FileStream(fileName, FileMode.Open, FileAccess.Read) | ||
| let bomBuffer = Array.zeroCreate 4 | ||
| fs.Read(bomBuffer, 0, 4) |> ignore |
There was a problem hiding this comment.
What do you mean?
There was a problem hiding this comment.
fs.Read(bomBuffer, 0, 4)
what happens if it's 3 bytes?
There was a problem hiding this comment.
Then the next line is most likely false or undefined.
Comparing the result with 4 would definitely make future readers more happy ;)
a6c516c to
9150a63
Compare
|
Updated with a better way to get the bytes to compare against. @forki What did you mean earlier with "What happens if it's 3 bytes"? If the file is shorter than what we're trying to read, |
|
thx! |
As mentioned in #2271, some project files have a BOM (created by VS), others don't (from Ionide/Forge), so to know what "unchanged" means, we have to probe the original file and set the encoding for writing the XML file accordingly. We only consider UTF-8 because it seems safe to assume all project files will have that.