aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-08-20 22:45:13 -0700
committerzotlabs <mike@macgirvin.com>2017-08-20 22:45:13 -0700
commit49cc952825bb9d8b2417f85d9d718b456357b364 (patch)
treef0285fdaa3d46013b80c3f2467a9886b37121b22 /util
parent31e62bd19e2fcfe70487ab38ee6b688e48a79c95 (diff)
downloadvolse-hubzilla-49cc952825bb9d8b2417f85d9d718b456357b364.tar.gz
volse-hubzilla-49cc952825bb9d8b2417f85d9d718b456357b364.tar.bz2
volse-hubzilla-49cc952825bb9d8b2417f85d9d718b456357b364.zip
util/dcp will now accept a directory as a destination. The directory must exist. Recursion is not yet supported.
Diffstat (limited to 'util')
-rwxr-xr-xutil/dcp86
1 files changed, 50 insertions, 36 deletions
diff --git a/util/dcp b/util/dcp
index 14ff5d5d3..e38725aa1 100755
--- a/util/dcp
+++ b/util/dcp
@@ -13,18 +13,16 @@ require_once('include/attach.php');
cli_startup();
-$srcfile = $argv[1];
-$dstfile = $argv[2];
-if($argc != 3) {
+if($argc <= 3) {
echo "Usage: " . $argv[0] . ' source destination' . "\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 must end with the destination filename (not a directory name).' . "\n";
+ echo 'destination should begin with store/$nickname/desired/path or $nickname/desired/path' . "\n";
echo 'Example: util/dcp /etc/motd store/joe/etc/motd' . "\n";
exit;
}
+ $dstfile = $argv[$argc - 1];
if(strpos($dstfile,'store/') === 0)
@@ -38,41 +36,57 @@ if($argc != 3) {
if(! $channel)
return;
+ $isadir = false;
- $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'],
- ];
+ $r = q("select * from attach where display_path = '%s' and uid = %d limit 1",
+ dbesc($dstfile),
+ intval($channel['channel_id'])
+ );
- $folder = '';
- if(dirname($dstfile)) {
- $x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
- if($x['success'])
- $folder = $x['data']['hash'];
+ if($r && $r[0]['is_dir']) {
+ $isadir = true;
+ $folder = $r[0]['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'];
+ }
+ }
+
+
+ for($x = 1; $x < ($argc - 1); $x ++) {
+ $srcfile = $argv[$x];
- $hash = random_string();
-
- $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;
+ $hash = random_string();
+
+ $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);
- if($sync)
+ $sync = attach_export_data($channel,$hash);
+ if($sync)
build_sync_packet($channel['channel_id'],array('file' => array($sync)));
-
+ }