mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
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
This commit is contained in:
parent
b82146eeee
commit
1b0c5e57e5
2 changed files with 16 additions and 2 deletions
16
apps/files_external/3rdparty/smb4php/smb.php
vendored
16
apps/files_external/3rdparty/smb4php/smb.php
vendored
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ abstract class StreamWrapper extends Common {
|
|||
}
|
||||
|
||||
public function filetype($path) {
|
||||
return filetype($this->constructUrl($path));
|
||||
return @filetype($this->constructUrl($path));
|
||||
}
|
||||
|
||||
public function file_exists($path) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue