summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/eg/van/empty
blob: 47ea21216eefb90acd7614cccdc863a903bdbe7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl

# $RCSfile: empty,v $$Revision: 1.4 $$Date: 2000/04/06 17:04:59 $

# This script empties a trashcan.

$recursive = shift if $ARGV[0] eq '-r';

@ARGV = '.' if $#ARGV < 0;

chop($pwd = `pwd`);

dir: foreach $dir (@ARGV) {
    unless (chdir $dir) {
	print stderr "Can't find directory $dir: $!\n";
	next dir;
    }
    if ($recursive) {
	do cmd('find . -name .deleted -exec /bin/rm -rf {} ;');
    }
    else {
	if (-d '.deleted') {
	    do cmd('rm -rf .deleted');
	}
	else {
	    if ($dir eq '.' && $pwd =~ m|/\.deleted$|) {
		chdir '..';
		do cmd('rm -rf .deleted');
	    }
	    else {
		print stderr "No trashcan found in directory $dir\n";
	    }
	}
    }
}
continue {
    chdir $pwd;
}

# force direct execution with no shell

sub cmd {
    system split(' ',join(' ',@_));
}