more work on file sync to clones, 60-70% test coverage, mostly working but many changes made during testing which themselves have not yet been tested
This commit is contained in:
parent
9831ad515d
commit
861f5232d3
@ -899,10 +899,60 @@ function sync_files($channel,$files) {
|
|||||||
$att['aid'] = $channel['channel_account_id'];
|
$att['aid'] = $channel['channel_account_id'];
|
||||||
$att['uid'] = $channel['channel_id'];
|
$att['uid'] = $channel['channel_id'];
|
||||||
|
|
||||||
|
|
||||||
|
// check for duplicate folder names with the same parent.
|
||||||
|
// If we have a duplicate that doesn't match this hash value
|
||||||
|
// change the name so that the contents won't be "covered over"
|
||||||
|
// by the existing directory. Use the same logic we use for
|
||||||
|
// duplicate files.
|
||||||
|
|
||||||
|
if(strpos($att['filename'],'.') !== false) {
|
||||||
|
$basename = substr($att['filename'],0,strrpos($att['filename'],'.'));
|
||||||
|
$ext = substr($att['filename'],strrpos($att['filename'],'.'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$basename = $att['filename'];
|
||||||
|
$ext = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder == '%s' and hash != '%s' ",
|
||||||
|
dbesc($basename . $ext),
|
||||||
|
dbesc($basename . '(%)' . $ext),
|
||||||
|
dbesc($att['folder']),
|
||||||
|
dbesc($att['hash'])
|
||||||
|
);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
$x = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$found = false;
|
||||||
|
foreach($r as $rr) {
|
||||||
|
if($rr['filename'] === $basename . '(' . $x . ')' . $ext) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($found)
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
while($found);
|
||||||
|
$att['filename'] = $basename . '(' . $x . ')' . $ext;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$att['filename'] = $basename . $ext;
|
||||||
|
|
||||||
|
// end duplicate detection
|
||||||
|
|
||||||
|
|
||||||
|
// is this a directory?
|
||||||
|
|
||||||
if($att['filetype'] === 'multipart/mixed' && $att['is_dir']) {
|
if($att['filetype'] === 'multipart/mixed' && $att['is_dir']) {
|
||||||
os_mkdir($newfname, STORAGE_DEFAULT_PERMISSIONS,true);
|
os_mkdir($newfname, STORAGE_DEFAULT_PERMISSIONS,true);
|
||||||
$att['data'] = $newfname;
|
$att['data'] = $newfname;
|
||||||
|
|
||||||
dbesc_array($att);
|
dbesc_array($att);
|
||||||
|
|
||||||
$r = dbq("INSERT INTO attach (`"
|
$r = dbq("INSERT INTO attach (`"
|
||||||
. implode("`, `", array_keys($att))
|
. implode("`, `", array_keys($att))
|
||||||
. "`) VALUES ('"
|
. "`) VALUES ('"
|
||||||
@ -912,13 +962,16 @@ function sync_files($channel,$files) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// it's a file
|
||||||
|
|
||||||
$time = datetime_convert();
|
$time = datetime_convert();
|
||||||
|
|
||||||
$parr = array('hash' => $channel['channel_hash'],
|
$parr = array('hash' => $channel['channel_hash'],
|
||||||
'time' => $time,
|
'time' => $time,
|
||||||
'resource' => $att['hash'],
|
'resource' => $att['hash'],
|
||||||
'revision' => 0,
|
'revision' => 0,
|
||||||
'sig' => rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])
|
'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey']))
|
||||||
);
|
);
|
||||||
|
|
||||||
$store_path = $newfname;
|
$store_path = $newfname;
|
||||||
@ -944,7 +997,6 @@ function sync_files($channel,$files) {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(! $attachment_stored) {
|
if(! $attachment_stored) {
|
||||||
|
@ -194,7 +194,7 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$link[0] = array(
|
$link[0] = array(
|
||||||
'rel' => 'alternate',
|
'rel' => 'alternate',
|
||||||
'type' => 'text/html',
|
'type' => 'text/html',
|
||||||
'href' => $url = rawurlencode(z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt()),
|
'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(),
|
||||||
'width' => $ph->getWidth(),
|
'width' => $ph->getWidth(),
|
||||||
'height' => $ph->getHeight()
|
'height' => $ph->getHeight()
|
||||||
);
|
);
|
||||||
@ -212,7 +212,7 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$link[1] = array(
|
$link[1] = array(
|
||||||
'rel' => 'alternate',
|
'rel' => 'alternate',
|
||||||
'type' => 'text/html',
|
'type' => 'text/html',
|
||||||
'href' => $url = rawurlencode(z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt()),
|
'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(),
|
||||||
'width' => $ph->getWidth(),
|
'width' => $ph->getWidth(),
|
||||||
'height' => $ph->getHeight()
|
'height' => $ph->getHeight()
|
||||||
);
|
);
|
||||||
@ -227,7 +227,7 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$link[2] = array(
|
$link[2] = array(
|
||||||
'rel' => 'alternate',
|
'rel' => 'alternate',
|
||||||
'type' => 'text/html',
|
'type' => 'text/html',
|
||||||
'href' => $url = rawurlencode(z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt()),
|
'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(),
|
||||||
'width' => $ph->getWidth(),
|
'width' => $ph->getWidth(),
|
||||||
'height' => $ph->getHeight()
|
'height' => $ph->getHeight()
|
||||||
);
|
);
|
||||||
@ -242,7 +242,7 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
$link[3] = array(
|
$link[3] = array(
|
||||||
'rel' => 'alternate',
|
'rel' => 'alternate',
|
||||||
'type' => 'text/html',
|
'type' => 'text/html',
|
||||||
'href' => $url = rawurlencode(z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt()),
|
'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(),
|
||||||
'width' => $ph->getWidth(),
|
'width' => $ph->getWidth(),
|
||||||
'height' => $ph->getHeight()
|
'height' => $ph->getHeight()
|
||||||
);
|
);
|
||||||
|
@ -2753,15 +2753,13 @@ function item_url_replace($channel,&$item,$old,$new,$oldnick = '') {
|
|||||||
$item['item_verified'] = 1;
|
$item['item_verified'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @fixme item['plink'] and item['llink']
|
$item['plink'] = str_replace($old,$new,$item['plink']);
|
||||||
|
|
||||||
str_replace($old,$new,$item['plink']);
|
|
||||||
if($oldnick)
|
if($oldnick)
|
||||||
str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['plink']);
|
$item['plink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['plink']);
|
||||||
|
|
||||||
str_replace($old,$new,$item['llink']);
|
$item['llink'] = str_replace($old,$new,$item['llink']);
|
||||||
if($oldnick)
|
if($oldnick)
|
||||||
str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['llink']);
|
$item['llink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['llink']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ function getfile_post(&$a) {
|
|||||||
$d1 = datetime_convert('UTC','UTC',"now + $slop minutes");
|
$d1 = datetime_convert('UTC','UTC',"now + $slop minutes");
|
||||||
$d2 = datetime_convert('UTC','UTC',"now - $slop minutes");
|
$d2 = datetime_convert('UTC','UTC',"now - $slop minutes");
|
||||||
|
|
||||||
if(($time > d1) || ($time < d2)) {
|
if(($time > $d1) || ($time < $d2)) {
|
||||||
logger('time outside allowable range');
|
logger('time outside allowable range');
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user