Rev 527 Rev 1938
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 if (count(glob("/tmp/wsvn-*"))<=40) // Omezeni na pocet soucasne stahovanych souboru 53 if (count(glob("/tmp/wsvn-*"))<=40) // Omezeni na pocet soucasne stahovanych souboru
54 { 54 {
-   55  
-   56 // Ošetření doběhnutí skriptu i když klient klikne jinam (smazání tmp)
-   57 ignore_user_abort(true);
-   58  
55 $tmpname1 = tempnam("temp", "wsvn-"); 59 $tmpname1 = tempnam("temp", "wsvn-");
56 $tmpname = $tmpname1; 60 $tmpname = $tmpname1;
57 $tmpname .= "dir"; 61 $tmpname .= "dir";
58 if (mkdir($tmpname)) 62 if (mkdir($tmpname))
59 { 63 {
60 // Get the name of the directory being archived 64 // Get the name of the directory being archived
61 $arcname = substr($path, 0, -1); 65 $arcname = substr($path, 0, -1);
62 $arcname = basename($arcname); 66 $arcname = basename($arcname);
63 if (empty($arcname)) 67 if (empty($arcname))
64 $arcname = $rep->name; 68 $arcname = $rep->name;
65 69
66 $svnrep->exportDirectory($path, $tmpname.DIRECTORY_SEPARATOR.$arcname, $rev); 70 $svnrep->exportDirectory($path, $tmpname.DIRECTORY_SEPARATOR.$arcname, $rev);
67 71
68 // ZIP it up 72 // ZIP it up
69 chdir($tmpname); 73 chdir($tmpname);
-   74 if (! connection_aborted())
70 exec("zip -r ".quote("$arcname")." ."); 75 exec("zip -r ".quote("$arcname")." .");
71 76
72 $size = filesize("$arcname.zip"); 77 $size = filesize("$arcname.zip");
73 78
74 // Give the file to the browser 79 // Give the file to the browser
75 80
76 if ($fp = @fopen("$arcname.zip","rb")) 81 if (!connection_aborted() && $fp = @fopen("$arcname.zip","rb"))
77 { 82 {
78 header("Content-Type: application/zip"); 83 header("Content-Type: application/zip");
79 header("Content-Length: $size"); 84 header("Content-Length: $size");
80 header("Content-Disposition: attachment; filename=\"".$rep->name."-$arcname.zip\""); 85 header("Content-Disposition: attachment; filename=\"".$rep->name."-$arcname.zip\"");
81 // Use a loop to transfer the data 4KB at a time. 86 // Use a loop to transfer the data 4KB at a time.
82 while(!feof($fp)) 87 while(!feof($fp))
83 { 88 {
84 echo fread($fp, 4096); 89 echo fread($fp, 4096);
85 ob_flush(); 90 ob_flush();
86 } 91 }
87 } 92 }
88 else 93 else
89 { 94 {
90 print "Unable to open file $arcname.zip"; 95 print "Unable to open file $arcname.zip";
91 } 96 }
92 97
93 fclose($fp); 98 fclose($fp);
94 99
95 chdir(".."); 100 chdir("..");
96 101
97 // Delete the directory. Why doesn't PHP have a generic recursive directory 102 // Delete the directory. Why doesn't PHP have a generic recursive directory
98 // deletion command? It's stupid. 103 // deletion command? It's stupid.
99 104
100 // if ($config->serverIsWindows) 105 // if ($config->serverIsWindows)
101 // { 106 // {
102 // $cmd = quoteCommand("rmdir /S /Q ".quote($tmpname), false); 107 // $cmd = quoteCommand("rmdir /S /Q ".quote($tmpname), false);
103 // } 108 // }
104 // else 109 // else
105 // { 110 // {
106 $cmd = quoteCommand("rm -fr ".quote($tmpname), false); 111 $cmd = quoteCommand("rm -fr ".quote($tmpname), false);
107 // } 112 // }
108 113
109 @exec($cmd); 114 @exec($cmd);
110 } 115 }
111 unlink($tmpname1); // Pomocny soubor smazeme az po smazani adresare 116 unlink($tmpname1); // Pomocny soubor smazeme az po smazani adresare
112 } 117 }
113 else 118 else
114 { 119 {
115 print "We are sorry. The server is overloaded..."; 120 print "We are sorry. The server is overloaded...";
116 } 121 }
117 ?> 122 ?>