You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case someone need reserve disk space before writing to file obvious strategy is following:
varfileStream=new FileStream();while(*){try{
fileStream.SetLength();
fileStream.Write();}catch(outof space ){}}
But unfortunately on real out of disk space situation SetLength doesn't restore position, so on next interation succesfull SetLength restores incorrect position (EOF) and Write goes beyong supposed end of file.
I suppose to add try/finally statement for position restoration in SetLengthCore, to make this behaviour safer. I think moving position is uninteded and exists as work around for WinAPI incompleteness. I can make PR if this change is supposed to be approved.
PS Unix version seems to be calling unnecessary seeks. FTruncate doesn't need it. It seems like copy-pasting from Win32 version. https://linux.die.net/man/2/truncate
The text was updated successfully, but these errors were encountered:
carlossanlop
changed the title
FileStream.SetLength doesn't return file pointer to orginal value on failure
FileStream.SetLength doesn't return file pointer to original value on failure
Mar 6, 2020
In case someone need reserve disk space before writing to file obvious strategy is following:
But unfortunately on real out of disk space situation SetLength doesn't restore position, so on next interation succesfull SetLength restores incorrect position (EOF) and Write goes beyong supposed end of file.
I suppose to add try/finally statement for position restoration in SetLengthCore, to make this behaviour safer. I think moving position is uninteded and exists as work around for WinAPI incompleteness. I can make PR if this change is supposed to be approved.
https://github.com/dotnet/coreclr/blob/684784fdb929f2c7d0173a317cb6e3ac6dc29d1a/src/mscorlib/shared/System/IO/FileStream.Win32.cs#L444
PS Unix version seems to be calling unnecessary seeks. FTruncate doesn't need it. It seems like copy-pasting from Win32 version.
https://linux.die.net/man/2/truncate
The text was updated successfully, but these errors were encountered: