streams/util/dmkdir

61 lines
1.4 KiB
Text
Raw Permalink Normal View History

2017-08-21 04:02:09 +00:00
#!/usr/bin/env php
<?php
2018-06-01 04:05:09 +00:00
2022-02-16 04:08:28 +00:00
use Code\Lib\Libsync;
use Code\Lib\Channel;
2018-06-01 04:05:09 +00:00
2017-08-21 04:02:09 +00:00
// file import to DAV utility
if(!file_exists('include/cli_startup.php')) {
2022-02-24 21:00:41 +00:00
echo 'Run dmkdir from the top level web directory, as util/dmkdir <args>' . PHP_EOL;
2017-08-21 04:02:09 +00:00
exit(1);
}
require_once('include/cli_startup.php');
require_once('include/attach.php');
cli_startup();
$dstfile = $argv[1];
if($argc != 2) {
2021-12-02 23:02:31 +00:00
echo 'Usage: ' . $argv[0] . ' directory' . "\n";
2017-08-21 04:02:09 +00:00
echo 'Always run from the toplevel web directory.' . "\n";
echo 'directory should begin with store/$nickname/desired/path or $nickname/desired/path' . "\n";
echo 'Example: util/dmkdir store/bob/photos/2017' . "\n";
exit;
}
if(strpos($dstfile,'store/') === 0)
$dstfile = substr($dstfile,6);
$nick = substr($dstfile,0,strpos($dstfile,'/'));
$dstfile = substr($dstfile,strlen($nick)+1);
2022-01-25 01:26:12 +00:00
$channel = Channel::from_username($nick);
2017-08-21 04:02:09 +00:00
if(! $channel)
return;
$arr = [
'pathname' => $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'],
];
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
if($x['success']) {
$hash = $x['data']['hash'];
$sync = attach_export_data($channel,$hash);
if($sync) {
2018-06-05 01:40:11 +00:00
Libsync::build_sync_packet($channel['channel_id'],array('file' => array($sync)));
}
}