in reply to Planning a Disk CleanUp Script

Hi, not a direct answer to your question, but rather a piece of advice from someone who has done a similar system: consider having your scripts assign the name of the file upon upload. I use sequential integers. The reason is that it's safer to use a known-safe filename (a script-assigned one) when you open up a filehandle to write the user's file to your filesystem, rather than the user-assigned filename which may contain nasty characters such as file piping etc.

I then update one text file that serves as an index, so I know what each numeric filename was originally called by the user, and can be used to refer to it.

Replies are listed 'Best First'.
Re (tilly) 2: Planning a Disk CleanUp Script
by tilly (Archbishop) on Jan 13, 2002 at 02:31 UTC
    A tip.

    Use random integers, not sequential ones.

    With sequential integers you have a race conditions. If 2 instances are trying to start at once, both can choose the same name and try to write to it, with bad results. Choose random integers and then test whether that one exists already and the odds of a bad race falls by several orders of magnitude.

    Either that or have the integer in question produced by a single source, such as an autoincrement field in a database.

      Thanks for the tip tilly. You are right to suggest random integers for the reasons you have outlined. But I do want to point out that anyone writing such a system should also look to the security section in the Camel on race conditions, and also be sure to use sysopen() rather than relying on an file existence test and open(), for the reasons outlined in the Camel.