Passed
Push — master ( 691aa8...315510 )
by Blizzz
17:05 queued 13s
created

PartFile::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Christoph Wurst <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program. If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
namespace OCA\DAV\Upload;
25
26
use OCA\DAV\Connector\Sabre\Directory;
27
use Sabre\DAV\Exception\Forbidden;
28
use Sabre\DAV\IFile;
29
30
/**
31
 * This class represents an Upload part which is not present on the storage itself
32
 * but handled directly by external storage services like S3 with Multipart Upload
33
 */
34
class PartFile implements IFile {
35
	/** @var Directory */
36
	private $root;
37
	/** @var array */
38
	private $partInfo;
39
40
	public function __construct(Directory $root, array $partInfo) {
41
		$this->root = $root;
42
		$this->partInfo = $partInfo;
43
	}
44
45
	/**
46
	 * @inheritdoc
47
	 */
48
	public function put($data) {
49
		throw new Forbidden('Permission denied to put into this file');
50
	}
51
52
	/**
53
	 * @inheritdoc
54
	 */
55
	public function get() {
56
		throw new Forbidden('Permission denied to get this file');
57
	}
58
59
	public function getPath() {
60
		return $this->root->getFileInfo()->getInternalPath() . '/' . $this->partInfo['PartNumber'];
61
	}
62
63
	/**
64
	 * @inheritdoc
65
	 */
66
	public function getContentType() {
67
		return 'application/octet-stream';
68
	}
69
70
	/**
71
	 * @inheritdoc
72
	 */
73
	public function getETag() {
74
		return $this->partInfo['ETag'];
75
	}
76
77
	/**
78
	 * @inheritdoc
79
	 */
80
	public function getSize() {
81
		return $this->partInfo['Size'];
82
	}
83
84
	/**
85
	 * @inheritdoc
86
	 */
87
	public function delete() {
88
		$this->root->delete();
89
	}
90
91
	/**
92
	 * @inheritdoc
93
	 */
94
	public function getName() {
95
		return $this->partInfo['PartNumber'];
96
	}
97
98
	/**
99
	 * @inheritdoc
100
	 */
101
	public function setName($name) {
102
		throw new Forbidden('Permission denied to rename this file');
103
	}
104
105
	/**
106
	 * @inheritdoc
107
	 */
108
	public function getLastModified() {
109
		return $this->partInfo['LastModified'];
110
	}
111
}
112