Re: Setting up automatic delete
From: wave++ (wavexx_at_oblio.yuv.info)
Date: 12/03/03
- Next message: Benjamin Gawert: "Re: IRIX freeware releases"
- Previous message: Jan-Frode Myklebust: "Re: Setting up automatic delete"
- In reply to: Ivan Rayner: "Re: Setting up automatic delete"
- Next in thread: Jan-Frode Myklebust: "Re: Setting up automatic delete"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 3 Dec 2003 09:23:01 GMT
On 2003-12-03, Ivan Rayner <ivanr@sgi.com> wrote:
>>|> Yes, forgot about spaces as I don't have to handle them usually :).
>>>> Using xargs however should be faster. If you have GNU utilities in place
>>|> you could do this:
>>
>>|> find ... -print0 | xargs -0 rm -f
>>
>>
>>| % mkdir delete_etc
>>| % for i in `seq 1 10000` ; do touch delete_etc/$i; done
>>| % touch delete_etc/passwd
>>| (have fam monitor and notify when files are being deleted
>>| from this dir)
>>| % mv delete_etc delete_etc-
>>| % ln -s /etc delete_etc
>>
>>|Whoops, where did my /etc/passwd go?
>>
>> Took me a bit of time to understand what's going on in Jan-Frode's code.
>>
>> The idea is that you create a file and leave it sitting around long
>> enough to be subject to the automatic cleaning. The 'find' process
>> will discover the name of the file, but will not, in the 'xargs' form
>> above, immediately delete the file; it will simply at first record
>> the file name. Then, after the name has been recorded and the deletions
>> start, you race the deletion section of the xargs and subtitute
>> a symbolic link at the -directory- level above. The rm is just fed
>> the -name- of the file+directory, so it goes ahead and follows
>> the symbolic link over to new location (not having been told that
>> it used to be a real directory before instead of a symlink),
>> and what gets deleted is the system file, not the user file. :(
A _true_ solution would consist in stat(2)-ing all files encountered
during the recursive scan to record inodes, and then verifing them when
removing the files themselves. As a futher optimization you can verify
inodes only on directories.
The problem however could still persist if you moved some files around
when scanning (assuming you unlink files immediately, you may still have
problems on large directory trees). You have to double-check that all
files resides inside the root you specify.
> Since find wouldn't follow symlinks, all you'd need to do is replace
> rm with a script which would check to see if any element in the path
> is a symlink and if it is, to unlink the symlink itself.
>
> This would reduce the window, but not remove it.
>
> I suppose you could have the script do the above check and if it passes
> create a hardlink to the the file and then remove it, do the check again and
> then either unlink the hardlinked file or rename it back to the original and
> remove the bogus symlink.
>
> Ivan
This case definitively deserves a dedicated tool :)
-- wave++ (also known, in some places, as "Yuri D'Elia") http://www.yuv.info/ The email address is fake (thanks swen)! You know how to contact me anyway.
- Next message: Benjamin Gawert: "Re: IRIX freeware releases"
- Previous message: Jan-Frode Myklebust: "Re: Setting up automatic delete"
- In reply to: Ivan Rayner: "Re: Setting up automatic delete"
- Next in thread: Jan-Frode Myklebust: "Re: Setting up automatic delete"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|