in reply to How long have you been sitting on my server?

Here's the rub: your policy is... unusual. You seem to be saying that your users can upload a file, but it cannot stay for more than 30 days. Is there anything preventing them from uploading it again as soon as you delete it? Can they upload the same file again before you delete it? (Simply overwriting the file with the same thing...)

If the answer to either of the previous two questions is yes you should write a script that scans the directories in question periodically and records the name of any new files and when they first appeared. Of course, you also have to remove files from your list when they are deleted. That of course will allow the user to upload the same file again as soon as you delete it from your database of files. If you don't take it off your list of files, they'll never be able to upload a file with the same name twice.

If your objective is to simply delete files which have not changed in 30 days, that's much easier and can be done with the ctime and mtime values. Here's the deal with ctime: it changes any time the file meta-data changes. This means that when the file was uploaded it's mtime was set to the time when the last write completed. Then the system changed the mtime! This caused the ctime to be set to the time when the mtime was altered. As long as you don't change the meta-data yourself you can do something like this:

$fl=$ARGV[0]; @st=stat($fl); $timeout=30*24*60*60; if($st[9] < (time()-$timeout) and $st[10] < (time()-$timeout)) { unlink $fl; }

The above example uses the stat() built-in subroutine. I tend to prefer it to the -M and -C routines operators but I'm sure you can use whichever you want. Note that stat() returns the mtime as the ninth value and ctime as the 10th and that the values are in seconds since 00:00 January 1, 1970 GMT. -M and -C return the time in a differenct format.

The above will cause the the file in $fl to be deleted if and only if no one has modified it in the last 30 days. This makes more sense to me, but it may not be what you're trying for...

Replies are listed 'Best First'.
Re: Re: How long have you been sitting on my server?
by John M. Dlugosz (Monsignor) on Jan 28, 2003 at 03:55 UTC
    Unusual? CPAN/PAUSE doesn't allow re-uploading a file, so it must remember the file names of every file that's ever been uploaded, forever, even after it's been deleted.
      I suppose that makes sense for an archive site... but I assumed it wasn't an archive site, because he's deleting files after only 30 days. There wouldn't be much on CPAN/PAUSE if that were the case, would there?