jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [dl.php] - Blame information for rev 1

 

Line No. Rev Author Line
11simandl<?php
2// WebSVN - Subversion repository viewing via the web using PHP
3// Copyright (C) 2004-2006 Tim Armes
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18//
19// --
20//
21// dl.php
22//
23// Create gz/tar files of the requested item
24 
25require_once("include/setup.php");
26require_once("include/svnlook.php");
27require_once("include/utils.php");
28 
29function removeDirectory($dir) {
30 if (is_dir($dir)) {
31 $dir = rtrim($dir, '/');
32 $handle = dir($dir);
33 while (($file = $handle->read()) !== false) {
34 if ($file == '.' || $file == '..') {
35 continue;
36 }
37 
38 $f = $dir.DIRECTORY_SEPARATOR.$file;
39 if (!is_link($f) && is_dir($f)) {
40 removeDirectory($f);
41 } else {
42 @unlink($f);
43 }
44 }
45 $handle->close();
46 @rmdir($dir);
47 return true;
48 }
49 return false;
50}
51 
52// Make sure that this operation is allowed
53 
54if (!$rep->isDownloadAllowed($path)) {
55 exit;
56}
57 
58$svnrep = new SVNRepository($rep);
59 
60// Fetch information about latest revision for this path
61if (empty($rev)) {
62 $history = $svnrep->getLog($path, 'HEAD', '', true, 1);
63} else {
64 $history = $svnrep->getLog($path, $rev, $rev - 1, true, 1);
65}
66$logEntry = $history->entries[0];
67 
68if (empty($rev)) {
69 $rev = $logEntry->rev;
70}
71 
72// Create a temporary directory. Here we have an unavoidable but highly
73// unlikely to occure race condition
74 
75$tmpname = tempnam($config->getTarballTmpDir(), 'wsvn');
76@unlink($tmpname);
77 
78if (mkdir($tmpname)) {
79 // Get the name of the directory being archived
80 $arcname = $path;
81 if (substr($arcname, -1) == '/') {
82 $arcname = substr($arcname, 0, -1);
83 }
84 $arcname = basename($arcname);
85 if ($arcname == '') {
86 $arcname = $rep->name;
87 }
88 
89 $arcname = $arcname.'.r'.$rev;
90 $tararc = $arcname.'.tar';
91 $gzarc = $arcname.'.tar.gz';
92 
93 $svnrep->exportDirectory($path, $tmpname.DIRECTORY_SEPARATOR.$arcname, $rev);
94 
95 // change to temp directory so that only relative paths are stored in tar
96 chdir($tmpname);
97 
98 // Set datetime of exported and directory to datetime of revision
99 $date = $logEntry->date;
100 $ts = substr($date, 0, 4).substr($date, 5, 2).substr($date, 8, 2).substr($date, 11, 2).substr($date, 14, 2).'.'.substr($date, 17, 2);
101 exec(quoteCommand($config->touch.' -t '.$ts.' '.quote($tmpname.DIRECTORY_SEPARATOR.$arcname)));
102 
103 // Create the tar file
104 exec(quoteCommand($config->tar.' -cf '.quote($tmpname.DIRECTORY_SEPARATOR.$tararc).' '.quote($arcname)));
105 
106 // Set datetime of tar file to datetime of revision
107 exec(quoteCommand($config->touch.' -t '.$ts.' '.quote($tmpname.DIRECTORY_SEPARATOR.$tararc)));
108 
109 // ZIP it up
110 exec(quoteCommand($config->gzip.' '.quote($tmpname.DIRECTORY_SEPARATOR.$tararc)));
111 
112 // Give the file to the browser
113 if (is_readable($tmpname.DIRECTORY_SEPARATOR.$gzarc)) {
114 $size = filesize($tmpname.DIRECTORY_SEPARATOR.$gzarc);
115 
116 header('Content-Type: application/x-gzip');
117 header('Content-Length: '.$size);
118 header('Content-Disposition: attachment; filename="'.$rep->name.'-'.$gzarc.'"');
119 
120 readfile($tmpname.DIRECTORY_SEPARATOR.$gzarc);
121 } else {
122 print'Unable to open file '.$gzarc;
123 }
124 
125 chdir('..');
126 
127 removeDirectory($tmpname);
128}

Powered by WebSVN 2.2.1