Archive for the 'Patterns' Category

Destruction Ray

Destrution Ray

Last year I am doing lots of code review, QA and work very close to production. Maybe the most destructive patter I saw during this competition was implemented in the following script:

cd ~/temp
find . -maxdepth 2 -type f -ctime +5 -exec rm {} \;

This script looks quite simple, isn’t it? It deletes some temporary files, which are older then 5 days, really simple, but… with one condition, when ~/temp folder missed because of any reason (NFS share wasn’t mounted or local drive failed or user hasn’t enough rights) this script will delete innocent files in the working directory (in case of cron this more probably will be the user home).

So always define a FULL path in the command which is select files for delete, not rely that the command above change the directory for it and you will not use this pattern.

No Comments »