summaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-22 18:18:08 +0100
committerVincent Petry <pvince81@owncloud.com>2013-11-25 11:17:38 +0100
commit1b0c5e57e5e4042ebb4f0e5956330a908645b61a (patch)
tree63e897969fb9c9ad4af967bb98fcfd02670c1829 /apps/files_external/3rdparty
parentb82146eeee2c969a53dd42cebf06ecfd31a0e286 (diff)
downloadnextcloud-server-1b0c5e57e5e4042ebb4f0e5956330a908645b61a.tar.gz
nextcloud-server-1b0c5e57e5e4042ebb4f0e5956330a908645b61a.zip
Fixed SMB rename function to overwrite target file
When uploading files through WebDAV, a part file is created and a rename operation is performed with the expectation that the part file overwrites an existing file, if any. This fix makes the SMB external storage delete the target file before renaming, as smbclient doesn't support overwrite on move/rename. Fixes #5348
Diffstat (limited to 'apps/files_external/3rdparty')
-rw-r--r--apps/files_external/3rdparty/smb4php/smb.php16
1 files changed, 15 insertions, 1 deletions
diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php
index 9650f809041..87638271f0e 100644
--- a/apps/files_external/3rdparty/smb4php/smb.php
+++ b/apps/files_external/3rdparty/smb4php/smb.php
@@ -302,6 +302,7 @@ class smb {
}
function rename ($url_from, $url_to) {
+ $replace = false;
list ($from, $to) = array (smb::parse_url($url_from), smb::parse_url($url_to));
if ($from['host'] <> $to['host'] ||
$from['share'] <> $to['share'] ||
@@ -314,7 +315,20 @@ class smb {
trigger_error('rename(): error in URL', E_USER_ERROR);
}
smb::clearstatcache ($url_from);
- $result = smb::execute ('rename "'.$from['path'].'" "'.$to['path'].'"', $to);
+ $cmd = '';
+ // check if target file exists
+ if (smb::url_stat($url_to)) {
+ // delete target file first
+ $cmd = 'del "' . $to['path'] . '"; ';
+ $replace = true;
+ }
+ $cmd .= 'rename "' . $from['path'] . '" "' . $to['path'] . '"';
+ $result = smb::execute($cmd, $to);
+ if ($replace) {
+ // clear again, else the cache will return the info
+ // from the old file
+ smb::clearstatcache ($url_to);
+ }
return $result !== false;
}