I was wondering if the following are bugs or expected behavior/wont change.
Take the following code:
<?php
$handle = fopen("file.txt", "w");
fwrite($handle, "SOME DATA");
unlink("file.txt");
if (fwrite($handle, "SOMEMORE") === FALSE) {
print "CANNOT WRITE";
} else {
print "Wrote Data";
}
fclose($handle);
?>
Under linux the file is deleted and the result is Wrote Data (even
though the last fwrite didnt do anything).
Under windows, the unlink()
call results in a permissions denied error.
Shouldn't linux not allow the file to be deleted with an open stream as
well?
Next, URI escpaing:
Stream URIs need to be escaped, but this isn't true with the filesystem.
$test = file_get_contents("t%20e"); // results in error
$test = file_get_contents("t e"); // reads the file "t e"
(same results using full URI file://....)
Why don't filesystem paths have to be escaped but other protocols do?
This is against the RFC as spaces should be escaped.
Behvavior is same on linux and win so not an OS issue.
Rob
On Fri, 05 Aug 2005 16:48:21 -0400
Rob Richards rrichards@ctindustries.net wrote:
I was wondering if the following are bugs or expected behavior/wont change.
Take the following code:
<?php
$handle = fopen("file.txt", "w");
fwrite($handle, "SOME DATA");
unlink("file.txt");
if (fwrite($handle, "SOMEMORE") === FALSE) {
print "CANNOT WRITE";
} else {
print "Wrote Data";
}
fclose($handle);
?>Under linux the file is deleted and the result is Wrote Data (even
though the last fwrite didnt do anything).
That's because on Linux data gets phisically deleted only when number of
hardlinks to it and number of open descriptors becomes 0.
It's perfectly fine to open & delete file and continue writing to/reading from it.
That's, btw, one of the well known methods used do get a temporary FD.
Under windows, the
unlink()
call results in a permissions denied error.
Yup =) Also on Windows you can't open a file already opened by someone.
Shouldn't linux not allow the file to be deleted with an open stream as
well?
No, why?
--
Wbr,
Antony Dovgal
Antony Dovgal wrote:
Shouldn't linux not allow the file to be deleted with an open stream as
well?No, why?
Dunno, kind of the reason I was asking. Just doesn't seem right that you
can be writing to a file, it gets deleted and you have no idea it was
deleted seeing that it tells you it did write data to the non-existant file.
Thanks for the explanation though.
Rob
Yup =) Also on Windows you can't open a file already opened by someone.
Actually, you can if the person that opened it says you can, it's just
that it's not the default mode for the file.
--Wez.