[Haskell-cafe] Windows: openFile gives permission deniedwhenfilein use
Antoine Latter
aslatter at gmail.com
Thu Dec 29 19:34:55 CET 2011
On Thu, Dec 29, 2011 at 12:28 PM, Donn Cave <donn at avvanta.com> wrote:
> Quoth Antoine Latter <aslatter at gmail.com>,
> ...
>> Would this program then loop:
>>
>> append fromFilePath toFilePath = do
>> str <- readFile fromFile
>> writeFile toFile str
>>
>> if 'from' and 'to' where the same file?
>>
>> Currently the locking prevents this.
>
> Do you mean, locking makes that work, or just makes it fail in a
> different way? Anyway, I think that's an example that would have
> the same issues without hGetContents - that is, any way you set
> out to overwrite a file by modifying its contents, you have the
> same problem.
>
Locking makes this fail with an exception, I think. Not locking would
make this mis-behave.
And lets pretend I wrote the function that was in my head:
append fromFilePath toFilePath = do
str <- readFile fromFile
appendFile toFile str
Here, without locking, I would expect to fill my disk up, whereas
previously my program would have crashed before writing out any data.
Maybe these are pathological examples, but they are (I think!) the
justification for having the locking in the first place.
Antoine
More information about the Haskell-Cafe
mailing list