diff options
author | Mario Vavti <mario@mariovavti.com> | 2016-08-31 09:41:07 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2016-08-31 09:41:07 +0200 |
commit | e9462ba14529b7172ba5a21e7985d24de91faa37 (patch) | |
tree | c2270ca2975f6683a361c5959894b6bbc954475d /include/attach.php | |
parent | 2b9322fc7d879fecbe334083bbd028538c985c54 (diff) | |
parent | b775a1aa0e36a74f0f937d85f458fd12af18a264 (diff) | |
download | volse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.tar.gz volse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.tar.bz2 volse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.zip |
resolve merge conflict
Diffstat (limited to 'include/attach.php')
-rw-r--r-- | include/attach.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/attach.php b/include/attach.php index ae7d71dc7..137d2b11c 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1995,6 +1995,52 @@ function get_filename_by_cloudname($cloudname, $channel, $storepath) { return null; } + +// recursively copy a directory into cloud files +function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpath) +{ + if (!is_dir($srcpath) || !is_readable($srcpath)) { + logger('Error reading source path: ' . $srcpath, LOGGER_NORMAL); + return false; + } + $nodes = array_diff(scandir($srcpath), array('.', '..')); + foreach ($nodes as $node) { + $clouddir = $cloudpath . '/' . $node; // Sub-folder in cloud files destination + $nodepath = $srcpath . '/' . $node; // Sub-folder in source path + if(is_dir($nodepath)) { + $x = attach_mkdirp($channel, $observer_hash, array('pathname' => $clouddir)); + if(!$x['success']) { + logger('Error creating cloud path: ' . $clouddir, LOGGER_NORMAL); + return false; + } + // Recursively call this function where the source and destination are the subfolders + $success = copy_folder_to_cloudfiles($channel, $observer_hash, $nodepath, $clouddir); + if(!$success) { + logger('Error copying contents of folder: ' . $nodepath, LOGGER_NORMAL); + return false; + } + } elseif (is_file($nodepath) && is_readable($nodepath)) { + $x = attach_store($channel, $observer_hash, 'import', + array( + 'directory' => $cloudpath, + 'src' => $nodepath, + 'filename' => $node, + 'filesize' => @filesize($nodepath), + 'preserve_original' => true) + ); + if(!$x['success']) { + logger('Error copying file: ' . $nodepath , LOGGER_NORMAL); + logger('Return value: ' . json_encode($x), LOGGER_NORMAL); + return false; + } + } else { + logger('Error scanning source path', LOGGER_NORMAL); + return false; + } + } + + return true; +} /** * attach_move() * This function performs an in place directory-to-directory move of a stored attachment or photo. |