File: dl.php

package info (click to toggle)
websvn 1.61-20
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 728 kB
  • ctags: 450
  • sloc: php: 3,333; pascal: 1,245; sh: 155; makefile: 49
file content (104 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

// WebSVN - Subversion repository viewing via the web using PHP
// Copyright (C) 2004 Tim Armes
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// --
//
// dl.php
//
// Create gz/tar files of the requested item

require_once("include/setup.inc");
require_once("include/svnlook.inc");
require_once("include/utils.inc");

// Make sure that this operation is allowed

if (!$rep->getAllowDownload())
   exit;

$svnrep = new SVNRepository($rep->path);

if ($path{0} != "/")
   $ppath = "/".$path;
else
   $ppath = $path;

// If there's no revision info, go to the lastest revision for this path
$history = $svnrep->getHistory($path);
$youngest = $history[0]["rev"];

if (empty($rev))
   $rev = $youngest;

// Create a temporary directory.  Here we have an unavoidable but highly
// unlikely to occure race condition

$tmpname = tempnam("temp", "wsvn");
unlink($tmpname);
if (mkdir($tmpname))
{
   // Get the name of the directory being archived
   $arcname = substr($path, 0, -1);
   $arcname = basename($arcname);
   if (empty($arcname))
      $arcname = $rep->name;

   $svnrep->exportDirectory($path, quote($tmpname.DIRECTORY_SEPARATOR.$arcname), $rev);
   
   // Create the tar file
   chdir($tmpname);
   exec($config->tar." -cf \"$arcname.tar\" \"$arcname\"");
   
   // ZIP it up
   exec($config->gzip." \"$arcname.tar\"");
   $size = filesize("$arcname.tar.gz");

   // Give the file to the browser

   if ($fp = @fopen("$arcname.tar.gz","rb"))
   {
      header("Content-Type: application/x-gzip");
      header("Content-Length: $size");
      header("Content-Disposition: attachment; filename=$arcname.tar.gz");
      @fpassthru($fp);
   }
   else
   {
      print "Unable to open file $arcname.tar.gz";
   }
   
   fclose($fp);
   
   chdir("..");

   // Delete the directory.  Why doesn't PHP have a generic recursive directory
   // deletion command?  It's stupid.

   if ($config->serverIsWindows)
   {
      $cmd = quoteCommand("rmdir /S /Q ".quote($tmpname), false);
   }
   else
   {
      $cmd = quoteCommand("rm -rf ".quote($tmpname), false);
   }
   
   @exec($cmd);
}
?>