From 035449e4a3f243dcaa43c34259d489c31d9c7ebf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 17 Aug 2017 23:43:54 -0700 Subject: util/dcp "(DAV-copy) copy file from local system to Hubzilla/red DAV" --- util/dcp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 util/dcp (limited to 'util/dcp') diff --git a/util/dcp b/util/dcp new file mode 100755 index 000000000..86c25259f --- /dev/null +++ b/util/dcp @@ -0,0 +1,73 @@ +#!/usr/bin/env php +' . PHP_EOL; + exit(1); +} + +require_once('include/cli_startup.php'); +require_once('include/attach.php'); + +cli_startup(); + +$srcfile = $argv[1]; +$dstfile = $argv[2]; + +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 'Example: util/dcp /etc/motd store/joe/etc/motd' . "\n"; + exit; +} + + + + if(strpos($dstfile,'store/') === 0) + $dstfile = substr($dstfile,6); + + $nick = substr($dstfile,0,strpos($dstfile,'/')); + + $dstfile = substr($dstfile,strlen($nick)+1); + + $channel = channelx_by_nick($nick); + if(! $channel) + return; + + + $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']; + } + + $arr = [ + 'src' => $srcfile, + 'filename' => basename($srcfile), + 'hash' => random_string(), + '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); + + -- cgit v1.2.3 From 31e62bd19e2fcfe70487ab38ee6b688e48a79c95 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 20 Aug 2017 21:24:58 -0700 Subject: a few file activities were not getting synced --- util/dcp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'util/dcp') diff --git a/util/dcp b/util/dcp index 86c25259f..14ff5d5d3 100755 --- a/util/dcp +++ b/util/dcp @@ -54,10 +54,12 @@ if($argc != 3) { $folder = $x['data']['hash']; } + $hash = random_string(); + $arr = [ 'src' => $srcfile, 'filename' => basename($srcfile), - 'hash' => random_string(), + 'hash' => $hash, 'allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], @@ -70,4 +72,7 @@ if($argc != 3) { attach_store($channel,$channel['channel_hash'],'import',$arr); - + $sync = attach_export_data($channel,$hash); + if($sync) + build_sync_packet($channel['channel_id'],array('file' => array($sync))); + -- cgit v1.2.3 From 49cc952825bb9d8b2417f85d9d718b456357b364 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 20 Aug 2017 22:45:13 -0700 Subject: util/dcp will now accept a directory as a destination. The directory must exist. Recursion is not yet supported. --- util/dcp | 86 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'util/dcp') 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))); - + } -- cgit v1.2.3 From 9f37dbc6dc1798b9b56a683ed1975adc318ff931 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 22 Aug 2017 18:29:51 -0700 Subject: util/dcp - support recursion and folders full of photos by importing files singly in separate processes - not yet tested --- util/dcp | 89 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 25 deletions(-) (limited to 'util/dcp') diff --git a/util/dcp b/util/dcp index e38725aa1..672117f4e 100755 --- a/util/dcp +++ b/util/dcp @@ -15,15 +15,15 @@ cli_startup(); if($argc <= 3) { - echo "Usage: " . $argv[0] . ' source destination' . "\n"; + echo "Usage: " . $argv[0] . ' src dstdir' . "\n"; echo 'Always run from the toplevel web directory.' . "\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"; + echo 'Example: util/dcp /etc/motd store/joe/etc' . "\n"; exit; } - $dstfile = $argv[$argc - 1]; - + $recursive = false; + $dstfile = $argv[$argc - 1]; if(strpos($dstfile,'store/') === 0) $dstfile = substr($dstfile,6); @@ -45,6 +45,7 @@ if($argc <= 3) { if($r && $r[0]['is_dir']) { $isadir = true; + $basepath = $dstfile; $folder = $r[0]['hash']; } else { @@ -64,29 +65,67 @@ if($argc <= 3) { } } - for($x = 1; $x < ($argc - 1); $x ++) { - $srcfile = $argv[$x]; - - $hash = random_string(); + if(($argv[$x] === '-r') || ($argv[$x] === '-R')) { + $recursive = true; + continue; + } - $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(is_dir($argv[$x])) { + if($recursive) { + dcp_recurse($channel,$argv[$x],$basepath,$folder); + } + else { + continue; + } + } + else { + $dstname = (($isadir) ? '' : basename($dstfile)); + $cmd = [ 'Importfile', $channel['channel_id'], $argv[$x], $folder, $dstname ]; + \Zotlabs\Daemon\Master::Summon($cmd); + } + } - if($folder) - $arr['folder'] = $folder; - - attach_store($channel,$channel['channel_hash'],'import',$arr); - $sync = attach_export_data($channel,$hash); - if($sync) - build_sync_packet($channel['channel_id'],array('file' => array($sync))); + function dcp_recurse($channel,$src,$basepath,$folder) { + $dir = opendir($src); + if($dir) { + while(($entry = readdir($dir)) !== false) { + if($entry === '.' || $entry === '..') + continue; + $dstfile = $basepath . '/' . $entry; + if(is_dir($src . '/' . $entry)) { + $r = q("select * from attach where display_path = '%s' and uid = %d limit 1", + dbesc($dstfile), + intval($channel['channel_id']) + ); + + if($r && $r[0]['is_dir']) { + $folder = $r[0]['hash']; + } + else { + + $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'], + ]; + + $folder = ''; + $x = attach_mkdirp($channel,$channel['channel_hash'],$arr); + if($x['success']) + $folder = $x['data']['hash']; + } + $basepath = $dstfile; + dcp_recurse($channel,$src . '/' . $entry,$basepath,$folder); + } + else { + $cmd = [ 'Importfile', $channel['channel_id'], $src . '/' . $entry, $folder ]; + \Zotlabs\Daemon\Master::Summon($cmd); + } + } + closedir($dir); + } } -- cgit v1.2.3 From 41ff8fdd375fcf395b547dd02f3bdcbb198ec0c1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 22 Aug 2017 20:32:02 -0700 Subject: test recursive dav copy --- util/dcp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'util/dcp') diff --git a/util/dcp b/util/dcp index 672117f4e..2817ad4f1 100755 --- a/util/dcp +++ b/util/dcp @@ -36,8 +36,20 @@ if($argc <= 3) { if(! $channel) return; + for($x = 1; $x < ($argc - 1); $x ++) { + if(($argv[$x] === '-r') || ($argv[$x] === '-R')) { + $recursive = true; + break; + } + } + + $isadir = false; + if(($recursive) || ($argc > 3)) + $isadir = true; + + $r = q("select * from attach where display_path = '%s' and uid = %d limit 1", dbesc($dstfile), intval($channel['channel_id']) @@ -49,8 +61,9 @@ if($argc <= 3) { $folder = $r[0]['hash']; } else { + $pathname = (($isadir) ? $dstfile : dirname($dstfile)); $arr = [ - 'pathname' => dirname($dstfile), + 'pathname' => $pathname, 'allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], @@ -58,7 +71,7 @@ if($argc <= 3) { ]; $folder = ''; - if(dirname($dstfile)) { + if($pathname && $isadir) { $x = attach_mkdirp($channel,$channel['channel_hash'],$arr); if($x['success']) $folder = $x['data']['hash']; @@ -67,7 +80,6 @@ if($argc <= 3) { for($x = 1; $x < ($argc - 1); $x ++) { if(($argv[$x] === '-r') || ($argv[$x] === '-R')) { - $recursive = true; continue; } @@ -93,6 +105,7 @@ if($argc <= 3) { while(($entry = readdir($dir)) !== false) { if($entry === '.' || $entry === '..') continue; + $dstfile = $basepath . '/' . $entry; if(is_dir($src . '/' . $entry)) { $r = q("select * from attach where display_path = '%s' and uid = %d limit 1", @@ -118,8 +131,7 @@ if($argc <= 3) { if($x['success']) $folder = $x['data']['hash']; } - $basepath = $dstfile; - dcp_recurse($channel,$src . '/' . $entry,$basepath,$folder); + dcp_recurse($channel,$src . '/' . $entry,$dstfile,$folder); } else { $cmd = [ 'Importfile', $channel['channel_id'], $src . '/' . $entry, $folder ]; -- cgit v1.2.3