util/dcp (server to cloud file copy) better handling when destination directory is the channel root

This commit is contained in:
zotlabs 2018-04-11 22:27:59 -07:00
parent 739a612824
commit 549f7a53b1

View File

@ -28,9 +28,14 @@ if($argc < 3) {
if(strpos($dstfile,'store/') === 0) if(strpos($dstfile,'store/') === 0)
$dstfile = substr($dstfile,6); $dstfile = substr($dstfile,6);
$nick = substr($dstfile,0,strpos($dstfile,'/')); if(strpos($dstfile,'/'))
$nick = substr($dstfile,0,strpos($dstfile,'/'));
$dstfile = substr($dstfile,strlen($nick)+1); $dstfile = substr($dstfile,strlen($nick)+1);
}
else {
$nick = $dstfile;
$dstfile = '';
}
$channel = channelx_by_nick($nick); $channel = channelx_by_nick($nick);
if(! $channel) if(! $channel)
@ -43,38 +48,45 @@ if($argc < 3) {
} }
} }
$rootdir = ((strlen(trim($dstfile,'/'))) ? false : true);
$isadir = false; $isadir = false;
if(($recursive) || ($argc > 3)) if(($recursive) || ($argc > 3))
$isadir = true; $isadir = true;
$r = q("select * from attach where display_path = '%s' and uid = %d limit 1", if($rootdir) {
dbesc($dstfile), $folder = '';
intval($channel['channel_id'])
);
if($r && $r[0]['is_dir']) {
$isadir = true;
$basepath = $dstfile;
$folder = $r[0]['hash'];
} }
else { else {
$pathname = (($isadir) ? $dstfile : dirname($dstfile));
$arr = [
'pathname' => $pathname,
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid'],
];
$folder = ''; $r = q("select * from attach where display_path = '%s' and uid = %d limit 1",
if($pathname && $isadir) { dbesc($dstfile),
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr); intval($channel['channel_id'])
if($x['success']) );
$folder = $x['data']['hash'];
if($r && $r[0]['is_dir']) {
$isadir = true;
$basepath = $dstfile;
$folder = $r[0]['hash'];
}
else {
$pathname = (($isadir) ? $dstfile : dirname($dstfile));
$arr = [
'pathname' => $pathname,
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid'],
];
$folder = '';
if($pathname && $isadir) {
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
if($x['success'])
$folder = $x['data']['hash'];
}
} }
} }