Removed /usr/local from CDPATH
[clearscm.git] / functions / tmpfiles
1 #!/bin/ksh
2 ################################################################################
3 #
4 # File:         tmpfiles
5 # Description:  Routines for handling temp files
6 # Author:       Andrew@DeFaria.com
7 # Created:      Tue Apr 15 14:20:02 PDT 1997
8 # Modified:
9 # Language:     Korn Shell
10 #
11 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 # This function will cleanup all temporary files used by the calling script
15 # providing that they are all prefixed with tmpprefix.
16 function cleanup {
17   debug "ENTER $0"
18   status=$?
19   if [ ! -z "$tmpprefix" -a $status -eq 0 ]; then
20     verbose "Cleaning up temp files..."
21     rm -f ${tmpprefix}*
22   else
23     debug "tmpprefix not set or status was not equal to 0 - no temporary
24 files cleaned!"
25   fi
26
27   debug "EXIT $0"
28   exit $status
29 } # cleanup
30
31 function arm_trap {
32   debug "ENTER $0"
33   if [ -z "$tmpprefix" ]; then
34     warning "The environment variable tmpprefix has not neen set up!\n\
35 Temporary files will not be cleaned up automatically!"
36   else
37     trap 'trap cleanup EXIT ERR' EXIT
38     debug "Cleanup will be called on EXIT or ERR signals"
39   fi
40
41   debug "EXIT $0"
42 } # arm_trap
43
44 function disarm_trap {
45   debug "ENTER $0"
46
47   trap 'trap - EXIT ERR' EXIT
48   debug "Cleanup will not be called on EXIT or ERR signals"
49   debug "EXIT $0"
50 } # disarm_trap