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