|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) by Ahmed Ammar <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
|
6
|
|
|
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
|
7
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
|
8
|
|
|
* permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|
9
|
|
|
* |
|
10
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
|
11
|
|
|
* Software. |
|
12
|
|
|
* |
|
13
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
|
14
|
|
|
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
15
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
16
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
namespace OCA\DAV\Upload; |
|
20
|
|
|
|
|
21
|
|
|
use OCA\DAV\Connector\Sabre\Directory; |
|
22
|
|
|
use Sabre\DAV\Exception\Forbidden; |
|
23
|
|
|
use Sabre\DAV\IFile; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class FutureFileZsync |
|
27
|
|
|
* |
|
28
|
|
|
* The FutureFileZsync is a SabreDav IFile which connects the chunked upload directory |
|
29
|
|
|
* with the AssemblyStreamZsync, who does the final assembly job |
|
30
|
|
|
* |
|
31
|
|
|
* @package OCA\DAV\Upload |
|
32
|
|
|
*/ |
|
33
|
|
|
class FutureFileZsync extends FutureFile { |
|
34
|
|
|
|
|
35
|
|
|
/** @var IFile */ |
|
36
|
|
|
private $backingFile = null; |
|
37
|
|
|
/** @var string */ |
|
38
|
|
|
private $fileLength = 0; |
|
39
|
|
|
|
|
40
|
|
|
static public function getFutureFileName() { |
|
41
|
|
|
return '.file.zsync'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
static public function isFutureFile() { |
|
45
|
|
|
$davUploadsTarget = '/dav/uploads'; |
|
46
|
|
|
|
|
47
|
|
|
// Check if pathinfo starts with dav uploads target and basename is future file basename |
|
48
|
|
|
if (isset($_SERVER['PATH_INFO']) |
|
49
|
|
|
&& pathinfo($_SERVER['PATH_INFO'], PATHINFO_BASENAME) === FutureFileZsync::getFutureFileName() |
|
50
|
|
|
&& (strpos($_SERVER['PATH_INFO'], $davUploadsTarget) === 0)) { |
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @inheritdoc |
|
59
|
|
|
*/ |
|
60
|
|
|
function get() { |
|
61
|
|
|
$nodes = $this->root->getChildren(); |
|
62
|
|
|
return $this->root->childExists('.zsync') && $this->backingFile && $this->fileLength ? |
|
63
|
|
|
AssemblyStreamZsync::wrap($nodes, $this->backingFile, $this->fileLength) : |
|
|
|
|
|
|
64
|
|
|
AssemblyStream::wrap($nodes); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param IFile $file |
|
69
|
|
|
*/ |
|
70
|
|
|
function setBackingFile(IFile $file) { |
|
71
|
|
|
$this->backingFile = $file; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param string $fileLength |
|
76
|
|
|
*/ |
|
77
|
|
|
function setFileLength($fileLength) { |
|
78
|
|
|
$this->fileLength = $fileLength; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: