Don't add a trailing slash in viewsvn::paths::out() - method 2
[viewsvn.git] / includes / repository.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # ViewSVN [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 /**
14 * Class that manages repositories and can produce lists of
15 * repositories
16 *
17 * @pacakge ViewSVN
18 */
19
20 /**
21 * Repository class that can list repositories and prepare
22 * them for use
23 *
24 * @package DeskPRO
25 * @version $Id$
26 */
27 class Repository
28 {
29 /**
30 * Array of valid repositories
31 * @var array
32 */
33 var $repositories = array();
34
35 /**
36 * Root path to the repository
37 * @var string
38 */
39 var $path;
40
41 /**
42 * Whether or not the path is a container
43 * @var bool
44 */
45 var $container;
46
47 /**
48 * Constructor: prepare for repository
49 *
50 * @param string Path to repository or container
51 * @param bool Whether the path is a container
52 */
53 function Repository($path, $iscontainer)
54 {
55 global $viewsvn;
56
57 $this->path = $viewsvn->fetch_sourcepath($path);
58 $this->container = (bool)$iscontainer;
59
60 if ($this->container)
61 {
62 if ($dir = @opendir($this->path))
63 {
64 while (($file = readdir($dir)) !== false)
65 {
66 if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db'))
67 {
68 $this->repositories[] = $file;
69 }
70 }
71 closedir($dir);
72 }
73 }
74 else
75 {
76 if (is_dir($this->path . 'db'))
77 {
78 $this->repositories[] = $this->path;
79 }
80 }
81
82 if (count($this->repositories) < 1)
83 {
84 $viewsvn->trigger->error('no valid repositories');
85 }
86 }
87
88 /**
89 * Returns a list of repositories
90 *
91 * @access public
92 *
93 * @return array List of repositories
94 */
95 function fetch_list()
96 {
97 return $this->repositories;
98 }
99
100 /**
101 * Returns a path to a repository
102 *
103 * @access public
104 *
105 * @param string Repository name
106 *
107 * @return string Full path to the repository
108 */
109 function fetch_path($repository = '')
110 {
111 global $viewsvn;
112
113 if (!in_array($repository, $this->fetch_list()))
114 {
115 $viewsvn->trigger->error('invalid repository name');
116 }
117
118 if ($this->container)
119 {
120 return 'file://' . $this->path . $repository . '/';
121 }
122 else
123 {
124 return 'file://' . $this->path . '/';
125 }
126 }
127
128 /**
129 * Verifies a path inside a repository
130 *
131 * @access public
132 *
133 * @param string Repository name
134 * @param string Path
135 *
136 * @return bool Validity
137 */
138 function verify($repos, $path)
139 {
140 global $viewsvn;
141
142 if ($repospath = $this->fetch_path($repos))
143 {
144 return true;
145 }
146 else
147 {
148 return false;
149 }
150 }
151 }
152
153 /*=====================================================================*\
154 || ###################################################################
155 || # $HeadURL$
156 || # $Id$
157 || ###################################################################
158 \*=====================================================================*/
159 ?>