Rev 514 Rev 515
1 <?php 1 <?php
2 # vim:et:ts=3:sts=3:sw=3:fdm=marker: 2 # vim:et:ts=3:sts=3:sw=3:fdm=marker:
3   3  
4 // WebSVN - Subversion repository viewing via the web using PHP 4 // WebSVN - Subversion repository viewing via the web using PHP
5 // Copyright © 2004-2006 Tim Armes, Matt Sicker 5 // Copyright © 2004-2006 Tim Armes, Matt Sicker
6 // 6 //
7 // This program is free software; you can redistribute it and/or modify 7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by 8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or 9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version. 10 // (at your option) any later version.
11 // 11 //
12 // This program is distributed in the hope that it will be useful, 12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details. 15 // GNU General Public License for more details.
16 // 16 //
17 // You should have received a copy of the GNU General Public License 17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software 18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // 20 //
21 // -- 21 // --
22 // 22 //
23 // dl.php 23 // dl.php
24 // 24 //
25 // Create gz/tar files of the requested item 25 // Create gz/tar files of the requested item
26   26  
27 require_once("include/setup.inc"); 27 require_once("include/setup.inc");
28 require_once("include/svnlook.inc"); 28 require_once("include/svnlook.inc");
29 require_once("include/utils.inc"); 29 require_once("include/utils.inc");
30   30  
31 // Make sure that this operation is allowed 31 // Make sure that this operation is allowed
32   32  
33 if (!$rep->isDownloadAllowed($path)) 33 if (!$rep->isDownloadAllowed($path))
34 exit; 34 exit;
35   35  
36 $svnrep = new SVNRepository($rep); 36 $svnrep = new SVNRepository($rep);
37   37  
38 if ($path{0} != "/") 38 if ($path{0} != "/")
39 $ppath = "/".$path; 39 $ppath = "/".$path;
40 else 40 else
41 $ppath = $path; 41 $ppath = $path;
42   42  
43 // If there's no revision info, go to the lastest revision for this path 43 // If there's no revision info, go to the lastest revision for this path
44 $history = $svnrep->getLog($path, "", "", true); 44 $history = $svnrep->getLog($path, "", "", true);
45 $youngest = $history->entries[0]->rev; 45 $youngest = $history->entries[0]->rev;
46   46  
47 if (empty($rev)) 47 if (empty($rev))
48 $rev = $youngest; 48 $rev = $youngest;
49   49  
50 // Create a temporary directory. Here we have an unavoidable but highly 50 // Create a temporary directory. Here we have an unavoidable but highly
51 // unlikely to occure race condition 51 // unlikely to occure race condition
52   52  
53 //$tmpfile1 = tempnam("temp", "wsvn"); -  
54 //$tmpfile2 = tempnam("temp", "wsvn"); 53 $tmpname = tempnam("temp", "wsvn"); //!!!
55 //$tmpname = $tmpfile1.$tmpfile2; -  
56 $tmpname = tempnam("temp", "wsvn"); 54 unlink($tmpname);
57 if (mkdir($tmpname)) 55 if (mkdir($tmpname))
58 { 56 {
59 // Get the name of the directory being archived 57 // Get the name of the directory being archived
60 $arcname = substr($path, 0, -1); 58 $arcname = substr($path, 0, -1);
61 $arcname = basename($arcname); 59 $arcname = basename($arcname);
62 if (empty($arcname)) 60 if (empty($arcname))
63 $arcname = $rep->name; 61 $arcname = $rep->name;
64   62  
65 $svnrep->exportDirectory($path, $tmpname.DIRECTORY_SEPARATOR.$arcname, $rev); 63 $svnrep->exportDirectory($path, $tmpname.DIRECTORY_SEPARATOR.$arcname, $rev);
66 64
67 // ZIP it up 65 // ZIP it up
68 chdir($tmpname); 66 chdir($tmpname);
69 exec("zip -r ".quote("$arcname")." ."); 67 exec("zip -r ".quote("$arcname")." .");
70 68
71 $size = filesize("$arcname.zip"); 69 $size = filesize("$arcname.zip");
72   70  
73 // Give the file to the browser 71 // Give the file to the browser
74   72  
75 if ($fp = @fopen("$arcname.zip","rb")) 73 if ($fp = @fopen("$arcname.zip","rb"))
76 { 74 {
77 header("Content-Type: application/zip"); 75 header("Content-Type: application/zip");
78 header("Content-Length: $size"); 76 header("Content-Length: $size");
79 header("Content-Disposition: attachment; filename=\"".$rep->name."-$arcname.zip\""); 77 header("Content-Disposition: attachment; filename=\"".$rep->name."-$arcname.zip\"");
80 // Use a loop to transfer the data 4KB at a time. 78 // Use a loop to transfer the data 4KB at a time.
81 while(!feof($fp)) 79 while(!feof($fp))
82 { 80 {
83 echo fread($fp, 4096); 81 echo fread($fp, 4096);
84 ob_flush(); 82 ob_flush();
85 } 83 }
86 } 84 }
87 else 85 else
88 { 86 {
89 print "Unable to open file $arcname.zip"; 87 print "Unable to open file $arcname.zip";
90 } 88 }
91 89
92 fclose($fp); 90 fclose($fp);
93 91
94 chdir(".."); 92 chdir("..");
95   93  
96 // Delete the directory. Why doesn't PHP have a generic recursive directory 94 // Delete the directory. Why doesn't PHP have a generic recursive directory
97 // deletion command? It's stupid. 95 // deletion command? It's stupid.
98   96  
99 // if ($config->serverIsWindows) 97 // if ($config->serverIsWindows)
100 // { 98 // {
101 // $cmd = quoteCommand("rmdir /S /Q ".quote($tmpname), false); 99 // $cmd = quoteCommand("rmdir /S /Q ".quote($tmpname), false);
102 // } 100 // }
103 // else 101 // else
104 // { 102 // {
105 $cmd = quoteCommand("rm -fr ".quote($tmpname), false); 103 $cmd = quoteCommand("rm -fr ".quote($tmpname), false);
106 // } 104 // }
107 105
108 @exec($cmd); 106 @exec($cmd);
109 } 107 }
110 unlink($tmpname); -  
111 //unlink($tmpfile2); -  
112 ?> 108 ?>