3
* Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
4
* This file is licensed under the Affero General Public License version 3 or
6
* See the COPYING-README file.
9
namespace OC\Files\Storage;
11
set_include_path(get_include_path() . PATH_SEPARATOR .
12
'/usr/share/php/irods/prods/src');
15
require_once 'ProdsConfig.inc.php';
16
require_once 'ProdsStreamer.class.php';
19
class iRODS extends \OC\Files\Storage\StreamWrapper{
26
private $use_logon_credentials;
29
public function __construct($params) {
30
if (isset($params['host'])) {
31
$this->host = $params['host'];
32
$this->port = isset($params['port']) ? $params['port'] : 1247;
33
$this->user = isset($params['user']) ? $params['user'] : '';
34
$this->password = isset($params['password']) ? $params['password'] : '';
35
$this->use_logon_credentials = ($params['use_logon_credentials'] === 'true');
36
$this->zone = $params['zone'];
37
$this->auth_mode = isset($params['auth_mode']) ? $params['auth_mode'] : '';
39
$this->root = isset($params['root']) ? $params['root'] : '/';
40
if ( ! $this->root || $this->root[0] !== '/') {
41
$this->root='/'.$this->root;
44
// take user and password from the session
45
if ($this->use_logon_credentials && \OC::$session->exists('irods-credentials'))
47
$params = \OC::$session->get('irods-credentials');
48
$this->user = $params['uid'];
49
$this->password = $params['password'];
52
//create the root folder if necessary
53
if ( ! $this->is_dir('')) {
57
throw new \Exception();
62
public static function login( $params ) {
63
\OC::$session->set('irods-credentials', $params);
66
public function getId(){
67
return 'irods::' . $this->user . '@' . $this->host . '/' . $this->root;
71
* construct the rods url
75
public function constructUrl($path) {
76
$path = rtrim($path,'/');
77
if ( $path === '' || $path[0] !== '/') {
82
$userWithZone = $this->user.'.'.$this->zone;
83
if ($this->auth_mode !== '') {
84
$userWithZone .= '.'.$this->auth_mode;
87
// url wrapper schema is named rods
88
return 'rods://'.$userWithZone.':'.$this->password.'@'.$this->host.':'.$this->port.$this->root.$path;
91
public function filetype($path) {
92
return @filetype($this->constructUrl($path));
95
public function mkdir($path) {
96
return @mkdir($this->constructUrl($path));
99
public function touch($path, $mtime=null) {
101
// we cannot set a time
102
if ($mtime != null) {
106
$path = $this->constructUrl($path);
108
// if the file doesn't exist we create it
109
if (!file_exists($path)) {
110
file_put_contents($path, '');
114
// mtime updates are not supported
119
* check if a file or folder has been updated since $time
120
* @param string $path
124
public function hasUpdated($path,$time) {
125
// this it a work around for folder mtimes -> we loop it's content
126
if ( $this->is_dir($path)) {
127
$actualTime=$this->collectionMTime($path);
128
return $actualTime>$time;
131
$actualTime=$this->filemtime($path);
132
return $actualTime>$time;
136
* get the best guess for the modification time of an iRODS collection
138
private function collectionMTime($path) {
139
$dh = $this->opendir($path);
140
$lastCTime = $this->filemtime($path);
141
if(is_resource($dh)) {
142
while (($file = readdir($dh)) !== false) {
143
if ($file != '.' and $file != '..') {
144
$time = $this->filemtime($file);
145
if ($time > $lastCTime) {