views:

10

answers:

2

I am using symlinks generated in PHP. They are generated when someone requests a download, and I want them to expire at the end of each day.

The problem is, what if someone starts downloading a symlink 1 minute before the end of the day and then I delete the symlink while they are downloading it...

My question is, to your knowledge will that individual downloading the symlink, right before I delete it, still be able to "download" the file? I am not worried about "resumable download" capability.. but will it make their download stop or break in some way?

+3  A: 

Yes you can do this.

On UNIX-like systems (including Linux), you don't delete files. You delete filenames. If you delete a file that someone else currently has open, the filename will be gone but the data will remain on disk until the file is closed.

Even more so with symlinks: if you delete a symlink the file data is still there, and any process with the file open refers to it by a file handle, not by filename.

So as long as you delete the symlink after your script opens the file, the download will complete without any trouble.

Artelius
Thanks a bunch!
Joe
+1  A: 

As long as the webserver keeps the file open until the download is complete, which I would expect it to. this will work fine. On Linux you could even remove the hardlink to a file and the webserver would still be able to read from it as long as it's kept open

Michael Mrozek
Thanks a bunch!
Joe