aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-04-26 19:21:08 -0700
committerMario Vavti <mario@mariovavti.com>2018-04-27 09:58:07 +0200
commite33d8c288b86bf42b2471df4cb963395ed1664b9 (patch)
tree9795d1fdbcf54126fb15d6a63b5c75f9c619703c
parent34fbcfdfaa70080b7c280ede2910f9a198a7ede2 (diff)
downloadvolse-hubzilla-e33d8c288b86bf42b2471df4cb963395ed1664b9.tar.gz
volse-hubzilla-e33d8c288b86bf42b2471df4cb963395ed1664b9.tar.bz2
volse-hubzilla-e33d8c288b86bf42b2471df4cb963395ed1664b9.zip
more testing of attach_move() uncovered some issues
-rw-r--r--include/attach.php130
1 files changed, 73 insertions, 57 deletions
diff --git a/include/attach.php b/include/attach.php
index 363005029..27bf0218a 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -2286,33 +2286,22 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
if(! ($c && $resource_id))
return false;
+
+ // find the resource to be moved
+
$r = q("select * from attach where hash = '%s' and uid = %d limit 1",
dbesc($resource_id),
intval($channel_id)
);
- if(! $r)
+ if(! $r) {
+ logger('resource_id not found');
return false;
+ }
$oldstorepath = dbunescbin($r[0]['content']);
- if($r[0]['is_dir']) {
- $move_success = true;
- $x = q("select hash from attach where folder = '%s' and uid = %d",
- dbesc($r[0]['hash']),
- intval($channel_id)
- );
- if($x) {
- foreach($x as $xv) {
- $rs = attach_move($channel_id,$xv['hash'],$r[0]['hash']);
- if(! $rs) {
- $move_success = false;
- break;
- }
- }
- }
- return $move_success;
- }
+ // find the resource we are moving to
if($new_folder_hash) {
$n = q("select * from attach where hash = '%s' and uid = %d and is_dir = 1 limit 1",
@@ -2326,6 +2315,10 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
$newstorepath = dbunescbin($n[0]['content']) . '/' . $resource_id;
}
else {
+
+ // root directory
+
+ $newdirname = EMPTY_STR;
$newstorepath = 'store/' . $c['channel_address'] . '/' . $resource_id;
}
@@ -2335,56 +2328,61 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
$filename = $r[0]['filename'];
- $s = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
- dbesc($filename),
- dbesc($new_folder_hash)
- );
+ // don't do duplicate check unless our parent folder has changed.
- if($s) {
- $overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
- if($overwrite) {
- /// @fixme
- return;
- }
- else {
- if(strpos($filename,'.') !== false) {
- $basename = substr($filename,0,strrpos($filename,'.'));
- $ext = substr($filename,strrpos($filename,'.'));
+ if($r[0]['folder'] !== $new_folder_hash) {
+
+ $s = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ",
+ dbesc($filename),
+ dbesc($new_folder_hash)
+ );
+
+ if($s) {
+ $overwrite = get_pconfig($channel_id,'system','overwrite_dup_files');
+ if($overwrite) {
+ /// @fixme
+ return;
}
else {
- $basename = $filename;
- $ext = '';
- }
+ if(strpos($filename,'.') !== false) {
+ $basename = substr($filename,0,strrpos($filename,'.'));
+ $ext = substr($filename,strrpos($filename,'.'));
+ }
+ else {
+ $basename = $filename;
+ $ext = '';
+ }
- $matches = false;
- if(preg_match('/(.*?)\([0-9]{1,}\)$/',$basename,$matches))
- $basename = $matches[1];
+ $matches = false;
+ if(preg_match('/(.*?)\([0-9]{1,}\)$/',$basename,$matches))
+ $basename = $matches[1];
- $v = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
- dbesc($basename . $ext),
- dbesc($basename . '(%)' . $ext),
- dbesc($new_folder_hash)
- );
+ $v = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
+ dbesc($basename . $ext),
+ dbesc($basename . '(%)' . $ext),
+ dbesc($new_folder_hash)
+ );
- if($v) {
- $x = 1;
+ if($v) {
+ $x = 1;
- do {
- $found = false;
- foreach($v as $vv) {
- if($vv['filename'] === $basename . '(' . $x . ')' . $ext) {
- $found = true;
- break;
+ do {
+ $found = false;
+ foreach($v as $vv) {
+ if($vv['filename'] === $basename . '(' . $x . ')' . $ext) {
+ $found = true;
+ break;
+ }
}
+ if($found)
+ $x++;
}
- if($found)
- $x++;
+ while($found);
+ $filename = $basename . '(' . $x . ')' . $ext;
}
- while($found);
- $filename = $basename . '(' . $x . ')' . $ext;
+ else
+ $filename = $basename . $ext;
}
- else
- $filename = $basename . $ext;
}
}
@@ -2423,6 +2421,24 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) {
);
}
+ if($r[0]['is_dir']) {
+ $move_success = true;
+ $x = q("select hash from attach where folder = '%s' and uid = %d",
+ dbesc($r[0]['hash']),
+ intval($channel_id)
+ );
+ if($x) {
+ foreach($x as $xv) {
+ $rs = attach_move($channel_id,$xv['hash'],$r[0]['hash']);
+ if(! $rs) {
+ $move_success = false;
+ break;
+ }
+ }
+ }
+ return $move_success;
+ }
+
return true;
}