MTrack/SCM/WorkingCopy.php
[web.mtrack] / MTrack / SCM / WorkingCopy.php
1 <?php
2  
3 abstract class MTrack_SCM_WorkingCopy {
4     public $dir;
5   
6     /** returns the root dir of the working copy */
7     function getDir() {
8         return $this->dir;
9     }
10   
11     /** add a file to the working copy */
12     abstract function addFile($path);
13     /** removes a file from the working copy */
14     abstract function delFile($path);
15     /** commit changes that are pending in the working copy */
16     abstract function commit($CS);
17     /** get an MTrackSCMFile representation of a file */
18     abstract function getFile($path);
19   
20     /** enumerates files in a path in the working copy */
21     function enumFiles($path)
22     {
23         return scandir($this->dir . DIRECTORY_SEPARATOR . $path);
24     }
25   
26     /** determines if a file exists in the working copy */
27     function file_exists($path)
28     {
29       return file_exists($this->dir . DIRECTORY_SEPARATOR . $path);
30     }
31   
32     function __destruct()
33     {
34         if (strlen($this->dir) > 1) {
35             $this->rmdir($this->dir);
36             
37             //System::rm('-r', $this->dir);
38         }
39     }
40     
41     function rmdir($dir) {
42         require_once 'System.php';
43         $rm = System::which('rm');
44         $cmd = "$rm -rf " . escapeshellarg($dir);
45         `$cmd`;
46         
47         
48     }
49     
50     function generateTempDir()
51     {
52         
53         /*$tn =  '/var/lib/php5/mtrackworkingdirlEwD96a';
54         if (file_exists($tn)) {
55             $this->rmdir($tn);
56         }
57         clearstatcache();
58         if (file_exists($tn)) {
59             die("OOPS");
60         }
61         return $tn;
62         */
63         $tn = tempnam(ini_get('session.save_path'),'mtrackworkingdir');
64         unlink($tn);
65         return $tn;
66         
67         
68     }
69     
70     
71 }