more work on dav - deletion and a bit more progress on OS storage

This commit is contained in:
friendica 2014-01-07 18:47:33 -08:00
parent b8564134aa
commit 4011837805
3 changed files with 62 additions and 15 deletions

View File

@ -111,6 +111,7 @@ function create_account($arr) {
$expires = ((x($arr,'expires')) ? intval($arr['expires']) : '0000-00-00 00:00:00');
$default_service_class = get_config('system','default_service_class');
if($default_service_class === false)
$default_service_class = '';

View File

@ -569,16 +569,19 @@ function attach_mkdir($channel,$observer_hash,$arr = null) {
$lpath = '';
$lfile = $arr['folder'];
$sql_options = permissions_sql($channel);
$sql_options = permissions_sql($channel['channel_id']);
do {
$r = q("select filename, hash, flags, folder from attach where uid = %d and hash = '%s' and ( flags & %d )
$sql_options limit 1",
intval($channel['channel_id']),
dbesc($lfile),
intval(ATTACH_FLAG_DIR)
);
if(! $r) {
logger('attach_mkdir: hash ' . $lfile . ' not found in ' . $lpath);
$ret['message'] = t('Path not found.');
return $ret;
}
@ -606,8 +609,8 @@ function attach_mkdir($channel,$observer_hash,$arr = null) {
intval(0),
intval(0),
dbesc($arr['folder']),
intval(ATTACH_FLAG_DIR),
dbesc(''),
intval(ATTACH_FLAG_DIR|ATTACH_FLAG_OS),
dbesc($path),
dbesc($created),
dbesc($created),
dbesc(($arr && array_key_exists('allow_cid',$arr)) ? $arr['allow_cid'] : $channel['channel_allow_cid']),
@ -672,6 +675,56 @@ function attach_change_permissions($channel_id,$resource,$allow_cid,$allow_gid,$
}
function attach_delete($channel_id,$resource) {
$r = q("select hash, flags from attach where hash = '%s' and uid = %d limit 1",
dbesc($resource),
intval($channel_id)
);
if(! $r)
return;
if($r[0]['flags'] & ATTACH_FLAG_DIR) {
$x = q("select hash, flags from attach where folder = '%s' and uid = %d",
dbesc($resource),
intval($channel_id)
);
if($x) {
foreach($x as $xx) {
attach_delete($channel_id,$xx['hash']);
}
}
}
if($r[0]['flags'] & ATTACH_FLAG_OS) {
$y = q("select data from attach where hash = '%s' and uid = %d limit 1",
dbesc($resource),
intval($channel_id)
);
if($y) {
if(is_dir($y[0]['data']))
@rmdir($y[0]['data']);
elseif(file_exists($y[0]['data']))
unlink($y[0]['data']);
}
}
$z = q("delete from attach where hash = '%s' and uid = %d limit 1",
dbesc($resource),
intval($channel_id)
);
return;
}
function pipe_streams($in, $out) {
$size = 0;
while (!feof($in))

View File

@ -21,7 +21,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
if(! $this->red_path)
$this->red_path = '/';
$this->auth = $auth_plugin;
logger('Red_Directory: ' . print_r($this,true));
// logger('Red_Directory: ' . print_r($this,true));
$this->folder_hash = '';
$this->getDir();
@ -414,19 +414,12 @@ class RedFile extends DAV\Node implements DAV\IFile {
function delete() {
if($this->data['flags'] & ATTACH_FLAG_OS) {
// FIXME delete physical file
if((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) {
throw new DAV\Exception\Forbidden('Permission denied.');
return;
}
if($this->data['flags'] & ATTACH_FLAG_DIR) {
// FIXME delete contents (recursive?)
}
// q("delete from attach where id = %d limit 1",
// intval($this->data['id'])
// );
attach_delete($this->auth->owner_id,$this->data['hash']);
}
}