Index: trunk/extensions/Deployment/includes/filesystems/Ssh2Filesystem.php |
— | — | @@ -155,132 +155,152 @@ |
156 | 156 | * @see Filesystem::changeFileGroup |
157 | 157 | */ |
158 | 158 | public function changeFileGroup( $file, $group, $recursive = false ) { |
159 | | - if ( !$this->exists( $file ) ) { |
160 | | - return false; |
161 | | - } |
162 | | - |
163 | | - if ( !$recursive || !$this->isDir( $file ) ) { |
164 | | - return $this->runCommand( sprintf( 'chgrp %o %s', $mode, escapeshellarg( $file ) ) ); |
165 | | - } |
166 | | - |
167 | | - return $this->runCommand( sprintf( 'chgrp -R %o %s', $mode, escapeshellarg( $file ) ) ); |
| 159 | + // FIXME? |
| 160 | + return $this->runCommandRecursivly( 'chgrp', $file, $recursive ); |
168 | 161 | } |
169 | 162 | |
170 | 163 | /** |
171 | 164 | * @see Filesystem::chmod |
172 | 165 | */ |
173 | 166 | public function chmod( $file, $mode = false, $recursive = false ) { |
174 | | - if ( !$this->exists( $file ) ) { |
175 | | - return false; |
176 | | - } |
177 | | - |
178 | | - if ( !$mode ) { |
179 | | - if ( $this->is_file($file) ) { |
180 | | - $mode = FS_CHMOD_FILE; |
181 | | - } |
182 | | - elseif ( $this->is_dir($file) ) { |
183 | | - $mode = FS_CHMOD_DIR; |
184 | | - } |
185 | | - else { |
186 | | - return false; |
187 | | - } |
188 | | - } |
189 | | - |
190 | | - if ( !$recursive || !$this->isDir( $file ) ) { |
191 | | - return $this->runCommand( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ) ); |
192 | | - } |
193 | | - |
194 | | - return $this->runCommand( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ) ); |
| 167 | + return $this->runCommandRecursivly( 'chmod', $file, $recursive, $mode ); |
195 | 168 | } |
196 | 169 | |
197 | 170 | /** |
198 | 171 | * @see Filesystem::chown |
199 | 172 | */ |
200 | 173 | public function chown( $file, $owner, $recursive = false ) { |
201 | | - if ( !$this->exists( $file ) ) { |
202 | | - return false; |
203 | | - } |
204 | | - |
205 | | - if ( ! $recursive || ! $this->is_dir($file) ) |
206 | | - return $this->run_command(sprintf('chown %o %s', $mode, escapeshellarg($file)), true); |
207 | | - return $this->run_command(sprintf('chown -R %o %s', $mode, escapeshellarg($file)), true); |
| 174 | + return $this->runCommandRecursivly( 'chown', $file, $recursive, $mode ); |
208 | 175 | } |
209 | 176 | |
210 | 177 | /** |
211 | 178 | * @see Filesystem::delete |
212 | 179 | */ |
213 | 180 | public function delete( $path, $recursive = false ) { |
| 181 | + if ( $this->isFile( $path ) ) { |
| 182 | + return ssh2_sftp_unlink( $this->sftp_link, $path ); |
| 183 | + } |
| 184 | + |
| 185 | + if ( !$recursive ) { |
| 186 | + return ssh2_sftp_rmdir( $this->sftp_link, $path ); |
| 187 | + } |
| 188 | + |
| 189 | + $filelist = $this->listDir( $path ); |
214 | 190 | |
| 191 | + if ( is_array( $filelist ) ) { |
| 192 | + foreach ( $filelist as $filename => $fileinf ) { |
| 193 | + $this->delete( $path . '/' . $filename, $recursive ); |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + return ssh2_sftp_rmdir( $this->sftpConnection, $path ); |
215 | 198 | } |
216 | 199 | |
217 | 200 | /** |
218 | 201 | * @see Filesystem::doCopy |
219 | 202 | */ |
220 | | - protected function doCopy( $from, $to ) { |
| 203 | + protected function doCopy( $source, $destination ) { |
| 204 | + $content = $this->get_contents( $source ); |
221 | 205 | |
| 206 | + if ( false === $content ) { |
| 207 | + return false; |
| 208 | + } |
| 209 | + |
| 210 | + return $this->writeToFile( $destination, $content ); |
222 | 211 | } |
223 | 212 | |
224 | 213 | /** |
225 | 214 | * @see Filesystem::doMove |
226 | 215 | */ |
227 | | - protected function doMove( $from, $to ) { |
228 | | - |
| 216 | + protected function doMove( $source, $destination ) { |
| 217 | + wfSuppressWarnings(); |
| 218 | + $ssh2_sftp_rename = ssh2_sftp_rename( $this->connection, $source, $destination ); |
| 219 | + wfRestoreWarnings(); |
| 220 | + return $ssh2_sftp_rename; |
229 | 221 | } |
230 | 222 | |
231 | 223 | /** |
232 | 224 | * @see Filesystem::exists |
233 | 225 | */ |
234 | 226 | public function exists( $file ) { |
235 | | - |
| 227 | + return file_exists( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ) ); |
236 | 228 | } |
237 | 229 | |
238 | 230 | /** |
239 | 231 | * @see Filesystem::getChmod |
240 | 232 | */ |
241 | 233 | public function getChmod( $file ) { |
242 | | - |
| 234 | + wfSuppressWarnings(); |
| 235 | + $fileperms = fileperms( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ); |
| 236 | + wfRestoreWarnings(); |
| 237 | + return substr( decoct( $fileperms ) ), 3 ); |
243 | 238 | } |
244 | 239 | |
245 | 240 | /** |
246 | 241 | * @see Filesystem::getContents |
247 | 242 | */ |
248 | 243 | public function getContents() { |
249 | | - |
| 244 | + return file_get_contents( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ) ); |
250 | 245 | } |
251 | 246 | |
252 | 247 | /** |
253 | | - * @see Filesystem::getCreationTime |
254 | | - */ |
255 | | - public function getCreationTime( $file ) { |
256 | | - |
257 | | - } |
258 | | - |
259 | | - /** |
260 | 248 | * @see Filesystem::getCurrentWorkingDir |
261 | 249 | */ |
262 | 250 | public function getCurrentWorkingDir() { |
| 251 | + $cwd = $this->runCommand( 'pwd' ); |
263 | 252 | |
| 253 | + if ( $cwd ) { |
| 254 | + $cwd = rtrim( $cwd, '/' ) . '/'; |
| 255 | + } |
| 256 | + |
| 257 | + return $cwd; |
264 | 258 | } |
265 | 259 | |
266 | 260 | /** |
267 | 261 | * @see Filesystem::getGroup |
268 | 262 | */ |
269 | 263 | public function getGroup( $file ) { |
| 264 | + wfSuppressWarnings(); |
| 265 | + $gid = filegroup( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ) ); |
| 266 | + wfRestoreWarnings(); |
270 | 267 | |
| 268 | + if ( !$gid ) { |
| 269 | + return false; |
| 270 | + } |
| 271 | + |
| 272 | + if ( !function_exists( 'posix_getgrgid' ) ) { |
| 273 | + return $gid; |
| 274 | + } |
| 275 | + |
| 276 | + $groupArray = posix_getgrgid( $gid ); |
| 277 | + return $groupArray['name']; |
271 | 278 | } |
272 | 279 | |
273 | 280 | /** |
274 | 281 | * @see Filesystem::getModificationTime |
275 | 282 | */ |
276 | 283 | public function getModificationTime( $file ) { |
277 | | - |
| 284 | + return filemtime( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ) ); |
278 | 285 | } |
279 | 286 | |
280 | 287 | /** |
281 | 288 | * @see Filesystem::getOwner |
282 | 289 | */ |
283 | 290 | public function getOwner( $file ) { |
| 291 | + wfSuppressWarnings(); |
| 292 | + $owneruid = filegroup( 'ssh2.sftp://' . $this->sftpConnection . '/' . ltrim( $file, '/' ) ); |
| 293 | + wfRestoreWarnings(); |
284 | 294 | |
| 295 | + if ( !$owneruid ) { |
| 296 | + return false; |
| 297 | + } |
| 298 | + |
| 299 | + if ( !function_exists( 'posix_getpwuid' ) ) { |
| 300 | + return $owneruid; |
| 301 | + } |
| 302 | + |
| 303 | + $ownerArray = posix_getpwuid( $owneruid ); |
| 304 | + return $ownerArray['name']; |
285 | 305 | } |
286 | 306 | |
287 | 307 | /** |
— | — | @@ -346,6 +366,30 @@ |
347 | 367 | |
348 | 368 | } |
349 | 369 | |
| 370 | + protected function runCommandRecursivly( $command, $file, $recursive, $mode = false ) { |
| 371 | + if ( !$this->exists( $file ) ) { |
| 372 | + return false; |
| 373 | + } |
| 374 | + |
| 375 | + if ( !$mode ) { |
| 376 | + if ( $this->is_file($file) ) { |
| 377 | + $mode = FS_CHMOD_FILE; |
| 378 | + } |
| 379 | + elseif ( $this->is_dir($file) ) { |
| 380 | + $mode = FS_CHMOD_DIR; |
| 381 | + } |
| 382 | + else { |
| 383 | + return false; |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + if ( !$recursive || !$this->isDir( $file ) ) { |
| 388 | + return $this->runCommand( $command . sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ) ); |
| 389 | + } |
| 390 | + |
| 391 | + return $this->runCommand( $command .sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ) ); |
| 392 | + } |
| 393 | + |
350 | 394 | /** |
351 | 395 | * Executes a command. |
352 | 396 | * |