summaryrefslogtreecommitdiff
path: root/shell/bin/rm.php
blob: c55de8ca5314d45ed8d11370585169dd93224c21 (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
<?php
class p_rm extends prog {
	static function recurse_rm($src) {
		if ( is_dir($src) ) {
			$dir = opendir($src);
			while(false !== ( $file = readdir($dir)) ) {
				if (( $file != '.' ) && ( $file != '..' )) {
					self::recurse_rm($src.'/'.$file);
				}
			}
			closedir($dir);
			rmdir($src);
		} else {
			self::rm($src);
		}
	}

	public static function rm($file) {
		chown($file,666);
		unlink($file);
	}

	public static function main($args, $env) {
		$me = array_shift($args);
		$flags = '';
		while (substr($args[0],0,1) == '-') {
			$flags .= array_shift($args);
		}
		$flags = preg_replace('/[ -]/','',$flags);
		foreach ($args as $file) {
			if (strpos($flags,'r')===false) { self::rm($file); }
			else {                    self::recurse_rm($file); }
		}
	}
}