I've got a lighttpd web server set up on a Debian 6 guest in Virtualbox 4. I've got the www directory in a virtualbox shared folder, so that I can develop a website in the Windows host.
My problem is that two otherwise identical files created by different text editors are served differently by lighttpd. Vim works as it should, but creating files with echo (or any other editor) produces files that look fine on disk but become corrupted once lighttpd serves them. This problem is only present when the document root is on a shared virtualbox folder. It might be easier to show this problem than explain it, so I did a test case below.
EDIT: This is some kind of caching issue, running echo 3 > /proc/sys/vm/drop_caches
before wget makes the downloaded file work fine. Still doesn't explain why vim isn't affected though...
root@Apricots:/var/www/xxx.org/http# vim vim.txt
(I type 'Line 1' into vim, on one line)
root@Apricots:/var/www/xxx.org/http# echo 'Line 1' >> echo.txt
root@Apricots:/var/www/xxx.org/http# md5sum vim.txt echo.txt
376cbf50d47a30459adca22b15964912 vim.txt
376cbf50d47a30459adca22b15964912 echo.txt
root@Apricots:/var/www/xxxt.org/http# cd ~
root@Apricots:~# wget xxx.org/vim.txt xxx.org/echo.txt
(The two files download OK)
root@Apricots:~# md5sum vim.txt echo.txt
376cbf50d47a30459adca22b15964912 vim.txt
376cbf50d47a30459adca22b15964912 echo.txt
root@Apricots:~# cat vim.txt
Line 1
root@Apricots:~# cat echo.txt
Line 1
root@Apricots:~# cd /var/www/xxx.org/http/
root@Apricots:/var/www/xxx.org/http# vim vim.txt
(I type 'Line 2' in a second line in vim)
root@Apricots:/var/www/xxx.org/http# echo 'Line 2' >> echo.txt
root@Apricots:/var/www/xxx.org/http# md5sum vim.txt echo.txt
ef3095884e8daf72dc4d2ea71306caa7 vim.txt
ef3095884e8daf72dc4d2ea71306caa7 echo.txt
root@Apricots:/var/www/xxx.org/http# cat vim.txt
Line 1
Line 2
root@Apricots:/var/www/xxx.org/http# cat echo.txt
Line 1
Line 2
root@Apricots:/var/www/xxx.org/http# cd ~
root@Apricots:~# rm vim.txt echo.txt
root@Apricots:~# wget xxx.org/vim.txt xxx.org/echo.txt
(They both download fine again)
root@Apricots:~# md5sum vim.txt echo.txt
ef3095884e8daf72dc4d2ea71306caa7 vim.txt
0b8835dcb6bb73c7a4eb25301101699a echo.txt
root@Apricots:~# cat vim.txt
Line 1
Line 2
root@Apricots:~# cat echo.txt
Line 1
root@Apricots:~# hexdump vim.txt
0000000 694c 656e 3120 4c0a 6e69 2065 0a32
000000e
root@Apricots:~# hexdump echo.txt
0000000 694c 656e 3120 000a 0000 0000 0000
000000e
root@Apricots:~# echo "what the hell just happened there??"
what the hell just happened there??