util/dcp will now accept a directory as a destination. The directory must exist. Recursion is not yet supported.
This commit is contained in:
parent
31e62bd19e
commit
49cc952825
82
util/dcp
82
util/dcp
@ -13,18 +13,16 @@ require_once('include/attach.php');
|
|||||||
|
|
||||||
cli_startup();
|
cli_startup();
|
||||||
|
|
||||||
$srcfile = $argv[1];
|
|
||||||
$dstfile = $argv[2];
|
|
||||||
|
|
||||||
if($argc != 3) {
|
if($argc <= 3) {
|
||||||
echo "Usage: " . $argv[0] . ' source destination' . "\n";
|
echo "Usage: " . $argv[0] . ' source destination' . "\n";
|
||||||
echo 'Always run from the toplevel web directory.' . "\n";
|
echo 'Always run from the toplevel web directory.' . "\n";
|
||||||
echo 'destination should begin with store/$nickname/desired/path/filename or $nickname/desired/path/filename' . "\n";
|
echo 'destination should begin with store/$nickname/desired/path or $nickname/desired/path' . "\n";
|
||||||
echo 'destination must end with the destination filename (not a directory name).' . "\n";
|
|
||||||
echo 'Example: util/dcp /etc/motd store/joe/etc/motd' . "\n";
|
echo 'Example: util/dcp /etc/motd store/joe/etc/motd' . "\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dstfile = $argv[$argc - 1];
|
||||||
|
|
||||||
|
|
||||||
if(strpos($dstfile,'store/') === 0)
|
if(strpos($dstfile,'store/') === 0)
|
||||||
@ -38,41 +36,57 @@ if($argc != 3) {
|
|||||||
if(! $channel)
|
if(! $channel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
$isadir = false;
|
||||||
|
|
||||||
$arr = [
|
$r = q("select * from attach where display_path = '%s' and uid = %d limit 1",
|
||||||
'pathname' => dirname($dstfile),
|
dbesc($dstfile),
|
||||||
'allow_cid' => $channel['channel_allow_cid'],
|
intval($channel['channel_id'])
|
||||||
'allow_gid' => $channel['channel_allow_gid'],
|
);
|
||||||
'deny_cid' => $channel['channel_deny_cid'],
|
|
||||||
'deny_gid' => $channel['channel_deny_gid'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$folder = '';
|
if($r && $r[0]['is_dir']) {
|
||||||
if(dirname($dstfile)) {
|
$isadir = true;
|
||||||
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
|
$folder = $r[0]['hash'];
|
||||||
if($x['success'])
|
}
|
||||||
$folder = $x['data']['hash'];
|
else {
|
||||||
|
$arr = [
|
||||||
|
'pathname' => dirname($dstfile),
|
||||||
|
'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(dirname($dstfile)) {
|
||||||
|
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
|
||||||
|
if($x['success'])
|
||||||
|
$folder = $x['data']['hash'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash = random_string();
|
|
||||||
|
|
||||||
$arr = [
|
for($x = 1; $x < ($argc - 1); $x ++) {
|
||||||
'src' => $srcfile,
|
$srcfile = $argv[$x];
|
||||||
'filename' => basename($srcfile),
|
|
||||||
'hash' => $hash,
|
|
||||||
'allow_cid' => $channel['channel_allow_cid'],
|
|
||||||
'allow_gid' => $channel['channel_allow_gid'],
|
|
||||||
'deny_cid' => $channel['channel_deny_cid'],
|
|
||||||
'deny_gid' => $channel['channel_deny_gid'],
|
|
||||||
'preserve_original' => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
if($folder)
|
$hash = random_string();
|
||||||
$arr['folder'] = $folder;
|
|
||||||
|
$arr = [
|
||||||
|
'src' => $srcfile,
|
||||||
|
'filename' => basename($srcfile),
|
||||||
|
'hash' => $hash,
|
||||||
|
'allow_cid' => $channel['channel_allow_cid'],
|
||||||
|
'allow_gid' => $channel['channel_allow_gid'],
|
||||||
|
'deny_cid' => $channel['channel_deny_cid'],
|
||||||
|
'deny_gid' => $channel['channel_deny_gid'],
|
||||||
|
'preserve_original' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
if($folder)
|
||||||
|
$arr['folder'] = $folder;
|
||||||
|
|
||||||
attach_store($channel,$channel['channel_hash'],'import',$arr);
|
attach_store($channel,$channel['channel_hash'],'import',$arr);
|
||||||
|
|
||||||
$sync = attach_export_data($channel,$hash);
|
$sync = attach_export_data($channel,$hash);
|
||||||
if($sync)
|
if($sync)
|
||||||
build_sync_packet($channel['channel_id'],array('file' => array($sync)));
|
build_sync_packet($channel['channel_id'],array('file' => array($sync)));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user