Passed
Push — master ( e165dc...217243 )
by Roeland
12:21 queued 10s
created
lib/public/Files/ObjectStore/IObjectStore.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -34,51 +34,51 @@
 block discarded – undo
34 34
  */
35 35
 interface IObjectStore {
36 36
 
37
-	/**
38
-	 * @return string the container or bucket name where objects are stored
39
-	 * @since 7.0.0
40
-	 */
41
-	public function getStorageId();
37
+    /**
38
+     * @return string the container or bucket name where objects are stored
39
+     * @since 7.0.0
40
+     */
41
+    public function getStorageId();
42 42
 
43
-	/**
44
-	 * @param string $urn the unified resource name used to identify the object
45
-	 * @return resource stream with the read data
46
-	 * @throws \Exception when something goes wrong, message will be logged
47
-	 * @throws NotFoundException if file does not exist
48
-	 * @since 7.0.0
49
-	 */
50
-	public function readObject($urn);
43
+    /**
44
+     * @param string $urn the unified resource name used to identify the object
45
+     * @return resource stream with the read data
46
+     * @throws \Exception when something goes wrong, message will be logged
47
+     * @throws NotFoundException if file does not exist
48
+     * @since 7.0.0
49
+     */
50
+    public function readObject($urn);
51 51
 
52
-	/**
53
-	 * @param string $urn the unified resource name used to identify the object
54
-	 * @param resource $stream stream with the data to write
55
-	 * @throws \Exception when something goes wrong, message will be logged
56
-	 * @since 7.0.0
57
-	 */
58
-	public function writeObject($urn, $stream);
52
+    /**
53
+     * @param string $urn the unified resource name used to identify the object
54
+     * @param resource $stream stream with the data to write
55
+     * @throws \Exception when something goes wrong, message will be logged
56
+     * @since 7.0.0
57
+     */
58
+    public function writeObject($urn, $stream);
59 59
 
60
-	/**
61
-	 * @param string $urn the unified resource name used to identify the object
62
-	 * @return void
63
-	 * @throws \Exception when something goes wrong, message will be logged
64
-	 * @since 7.0.0
65
-	 */
66
-	public function deleteObject($urn);
60
+    /**
61
+     * @param string $urn the unified resource name used to identify the object
62
+     * @return void
63
+     * @throws \Exception when something goes wrong, message will be logged
64
+     * @since 7.0.0
65
+     */
66
+    public function deleteObject($urn);
67 67
 
68
-	/**
69
-	 * Check if an object exists in the object store
70
-	 *
71
-	 * @param string $urn
72
-	 * @return bool
73
-	 * @since 16.0.0
74
-	 */
75
-	public function objectExists($urn);
68
+    /**
69
+     * Check if an object exists in the object store
70
+     *
71
+     * @param string $urn
72
+     * @return bool
73
+     * @since 16.0.0
74
+     */
75
+    public function objectExists($urn);
76 76
 
77
-	/**
78
-	 * @param string $from the unified resource name used to identify the source object
79
-	 * @param string $to the unified resource name used to identify the target object
80
-	 * @return void
81
-	 * @since 21.0.0
82
-	 */
83
-	public function copyObject($from, $to);
77
+    /**
78
+     * @param string $from the unified resource name used to identify the source object
79
+     * @param string $to the unified resource name used to identify the target object
80
+     * @return void
81
+     * @since 21.0.0
82
+     */
83
+    public function copyObject($from, $to);
84 84
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/Swift.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -37,122 +37,122 @@
 block discarded – undo
37 37
 const SWIFT_SEGMENT_SIZE = 1073741824; // 1GB
38 38
 
39 39
 class Swift implements IObjectStore {
40
-	/**
41
-	 * @var array
42
-	 */
43
-	private $params;
44
-
45
-	/** @var SwiftFactory */
46
-	private $swiftFactory;
47
-
48
-	public function __construct($params, SwiftFactory $connectionFactory = null) {
49
-		$this->swiftFactory = $connectionFactory ?: new SwiftFactory(
50
-			\OC::$server->getMemCacheFactory()->createDistributed('swift::'),
51
-			$params,
52
-			\OC::$server->getLogger()
53
-		);
54
-		$this->params = $params;
55
-	}
56
-
57
-	/**
58
-	 * @return \OpenStack\ObjectStore\v1\Models\Container
59
-	 * @throws StorageAuthException
60
-	 * @throws \OCP\Files\StorageNotAvailableException
61
-	 */
62
-	private function getContainer() {
63
-		return $this->swiftFactory->getContainer();
64
-	}
65
-
66
-	/**
67
-	 * @return string the container name where objects are stored
68
-	 */
69
-	public function getStorageId() {
70
-		if (isset($this->params['bucket'])) {
71
-			return $this->params['bucket'];
72
-		}
73
-
74
-		return $this->params['container'];
75
-	}
76
-
77
-	/**
78
-	 * @param string $urn the unified resource name used to identify the object
79
-	 * @param resource $stream stream with the data to write
80
-	 * @throws \Exception from openstack lib when something goes wrong
81
-	 */
82
-	public function writeObject($urn, $stream) {
83
-		$tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite');
84
-		file_put_contents($tmpFile, $stream);
85
-		$handle = fopen($tmpFile, 'rb');
86
-
87
-		if (filesize($tmpFile) < SWIFT_SEGMENT_SIZE) {
88
-			$this->getContainer()->createObject([
89
-				'name' => $urn,
90
-				'stream' => stream_for($handle),
91
-			]);
92
-		} else {
93
-			$this->getContainer()->createLargeObject([
94
-				'name' => $urn,
95
-				'stream' => stream_for($handle),
96
-				'segmentSize' => SWIFT_SEGMENT_SIZE,
97
-			]);
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * @param string $urn the unified resource name used to identify the object
103
-	 * @return resource stream with the read data
104
-	 * @throws \Exception from openstack or GuzzleHttp libs when something goes wrong
105
-	 * @throws NotFoundException if file does not exist
106
-	 */
107
-	public function readObject($urn) {
108
-		try {
109
-			$publicUri = $this->getContainer()->getObject($urn)->getPublicUri();
110
-			$tokenId = $this->swiftFactory->getCachedTokenId();
111
-
112
-			$response = (new Client())->request('GET', $publicUri,
113
-				[
114
-					'stream' => true,
115
-					'headers' => [
116
-						'X-Auth-Token' => $tokenId,
117
-						'Cache-Control' => 'no-cache',
118
-					],
119
-				]
120
-			);
121
-		} catch (BadResponseException $e) {
122
-			if ($e->getResponse() && $e->getResponse()->getStatusCode() === 404) {
123
-				throw new NotFoundException("object $urn not found in object store");
124
-			} else {
125
-				throw $e;
126
-			}
127
-		}
128
-
129
-		return RetryWrapper::wrap($response->getBody()->detach());
130
-	}
131
-
132
-	/**
133
-	 * @param string $urn Unified Resource Name
134
-	 * @return void
135
-	 * @throws \Exception from openstack lib when something goes wrong
136
-	 */
137
-	public function deleteObject($urn) {
138
-		$this->getContainer()->getObject($urn)->delete();
139
-	}
140
-
141
-	/**
142
-	 * @return void
143
-	 * @throws \Exception from openstack lib when something goes wrong
144
-	 */
145
-	public function deleteContainer() {
146
-		$this->getContainer()->delete();
147
-	}
148
-
149
-	public function objectExists($urn) {
150
-		return $this->getContainer()->objectExists($urn);
151
-	}
152
-
153
-	public function copyObject($from, $to) {
154
-		$this->getContainer()->getObject($from)->copy([
155
-			'destination' => $this->getContainer()->name . '/' . $to
156
-		]);
157
-	}
40
+    /**
41
+     * @var array
42
+     */
43
+    private $params;
44
+
45
+    /** @var SwiftFactory */
46
+    private $swiftFactory;
47
+
48
+    public function __construct($params, SwiftFactory $connectionFactory = null) {
49
+        $this->swiftFactory = $connectionFactory ?: new SwiftFactory(
50
+            \OC::$server->getMemCacheFactory()->createDistributed('swift::'),
51
+            $params,
52
+            \OC::$server->getLogger()
53
+        );
54
+        $this->params = $params;
55
+    }
56
+
57
+    /**
58
+     * @return \OpenStack\ObjectStore\v1\Models\Container
59
+     * @throws StorageAuthException
60
+     * @throws \OCP\Files\StorageNotAvailableException
61
+     */
62
+    private function getContainer() {
63
+        return $this->swiftFactory->getContainer();
64
+    }
65
+
66
+    /**
67
+     * @return string the container name where objects are stored
68
+     */
69
+    public function getStorageId() {
70
+        if (isset($this->params['bucket'])) {
71
+            return $this->params['bucket'];
72
+        }
73
+
74
+        return $this->params['container'];
75
+    }
76
+
77
+    /**
78
+     * @param string $urn the unified resource name used to identify the object
79
+     * @param resource $stream stream with the data to write
80
+     * @throws \Exception from openstack lib when something goes wrong
81
+     */
82
+    public function writeObject($urn, $stream) {
83
+        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite');
84
+        file_put_contents($tmpFile, $stream);
85
+        $handle = fopen($tmpFile, 'rb');
86
+
87
+        if (filesize($tmpFile) < SWIFT_SEGMENT_SIZE) {
88
+            $this->getContainer()->createObject([
89
+                'name' => $urn,
90
+                'stream' => stream_for($handle),
91
+            ]);
92
+        } else {
93
+            $this->getContainer()->createLargeObject([
94
+                'name' => $urn,
95
+                'stream' => stream_for($handle),
96
+                'segmentSize' => SWIFT_SEGMENT_SIZE,
97
+            ]);
98
+        }
99
+    }
100
+
101
+    /**
102
+     * @param string $urn the unified resource name used to identify the object
103
+     * @return resource stream with the read data
104
+     * @throws \Exception from openstack or GuzzleHttp libs when something goes wrong
105
+     * @throws NotFoundException if file does not exist
106
+     */
107
+    public function readObject($urn) {
108
+        try {
109
+            $publicUri = $this->getContainer()->getObject($urn)->getPublicUri();
110
+            $tokenId = $this->swiftFactory->getCachedTokenId();
111
+
112
+            $response = (new Client())->request('GET', $publicUri,
113
+                [
114
+                    'stream' => true,
115
+                    'headers' => [
116
+                        'X-Auth-Token' => $tokenId,
117
+                        'Cache-Control' => 'no-cache',
118
+                    ],
119
+                ]
120
+            );
121
+        } catch (BadResponseException $e) {
122
+            if ($e->getResponse() && $e->getResponse()->getStatusCode() === 404) {
123
+                throw new NotFoundException("object $urn not found in object store");
124
+            } else {
125
+                throw $e;
126
+            }
127
+        }
128
+
129
+        return RetryWrapper::wrap($response->getBody()->detach());
130
+    }
131
+
132
+    /**
133
+     * @param string $urn Unified Resource Name
134
+     * @return void
135
+     * @throws \Exception from openstack lib when something goes wrong
136
+     */
137
+    public function deleteObject($urn) {
138
+        $this->getContainer()->getObject($urn)->delete();
139
+    }
140
+
141
+    /**
142
+     * @return void
143
+     * @throws \Exception from openstack lib when something goes wrong
144
+     */
145
+    public function deleteContainer() {
146
+        $this->getContainer()->delete();
147
+    }
148
+
149
+    public function objectExists($urn) {
150
+        return $this->getContainer()->objectExists($urn);
151
+    }
152
+
153
+    public function copyObject($from, $to) {
154
+        $this->getContainer()->getObject($from)->copy([
155
+            'destination' => $this->getContainer()->name . '/' . $to
156
+        ]);
157
+    }
158 158
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@
 block discarded – undo
152 152
 
153 153
 	public function copyObject($from, $to) {
154 154
 		$this->getContainer()->getObject($from)->copy([
155
-			'destination' => $this->getContainer()->name . '/' . $to
155
+			'destination' => $this->getContainer()->name.'/'.$to
156 156
 		]);
157 157
 	}
158 158
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/S3ObjectTrait.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -35,97 +35,97 @@
 block discarded – undo
35 35
 use OC\Files\Stream\SeekableHttpStream;
36 36
 
37 37
 trait S3ObjectTrait {
38
-	/**
39
-	 * Returns the connection
40
-	 *
41
-	 * @return S3Client connected client
42
-	 * @throws \Exception if connection could not be made
43
-	 */
44
-	abstract protected function getConnection();
38
+    /**
39
+     * Returns the connection
40
+     *
41
+     * @return S3Client connected client
42
+     * @throws \Exception if connection could not be made
43
+     */
44
+    abstract protected function getConnection();
45 45
 
46
-	/**
47
-	 * @param string $urn the unified resource name used to identify the object
48
-	 * @return resource stream with the read data
49
-	 * @throws \Exception when something goes wrong, message will be logged
50
-	 * @since 7.0.0
51
-	 */
52
-	public function readObject($urn) {
53
-		return SeekableHttpStream::open(function ($range) use ($urn) {
54
-			$command = $this->getConnection()->getCommand('GetObject', [
55
-				'Bucket' => $this->bucket,
56
-				'Key' => $urn,
57
-				'Range' => 'bytes=' . $range,
58
-			]);
59
-			$request = \Aws\serialize($command);
60
-			$headers = [];
61
-			foreach ($request->getHeaders() as $key => $values) {
62
-				foreach ($values as $value) {
63
-					$headers[] = "$key: $value";
64
-				}
65
-			}
66
-			$opts = [
67
-				'http' => [
68
-					'protocol_version' => 1.1,
69
-					'header' => $headers,
70
-				],
71
-			];
46
+    /**
47
+     * @param string $urn the unified resource name used to identify the object
48
+     * @return resource stream with the read data
49
+     * @throws \Exception when something goes wrong, message will be logged
50
+     * @since 7.0.0
51
+     */
52
+    public function readObject($urn) {
53
+        return SeekableHttpStream::open(function ($range) use ($urn) {
54
+            $command = $this->getConnection()->getCommand('GetObject', [
55
+                'Bucket' => $this->bucket,
56
+                'Key' => $urn,
57
+                'Range' => 'bytes=' . $range,
58
+            ]);
59
+            $request = \Aws\serialize($command);
60
+            $headers = [];
61
+            foreach ($request->getHeaders() as $key => $values) {
62
+                foreach ($values as $value) {
63
+                    $headers[] = "$key: $value";
64
+                }
65
+            }
66
+            $opts = [
67
+                'http' => [
68
+                    'protocol_version' => 1.1,
69
+                    'header' => $headers,
70
+                ],
71
+            ];
72 72
 
73
-			$context = stream_context_create($opts);
74
-			return fopen($request->getUri(), 'r', false, $context);
75
-		});
76
-	}
73
+            $context = stream_context_create($opts);
74
+            return fopen($request->getUri(), 'r', false, $context);
75
+        });
76
+    }
77 77
 
78
-	/**
79
-	 * @param string $urn the unified resource name used to identify the object
80
-	 * @param resource $stream stream with the data to write
81
-	 * @throws \Exception when something goes wrong, message will be logged
82
-	 * @since 7.0.0
83
-	 */
84
-	public function writeObject($urn, $stream) {
85
-		$count = 0;
86
-		$countStream = CallbackWrapper::wrap($stream, function ($read) use (&$count) {
87
-			$count += $read;
88
-		});
78
+    /**
79
+     * @param string $urn the unified resource name used to identify the object
80
+     * @param resource $stream stream with the data to write
81
+     * @throws \Exception when something goes wrong, message will be logged
82
+     * @since 7.0.0
83
+     */
84
+    public function writeObject($urn, $stream) {
85
+        $count = 0;
86
+        $countStream = CallbackWrapper::wrap($stream, function ($read) use (&$count) {
87
+            $count += $read;
88
+        });
89 89
 
90
-		$uploader = new MultipartUploader($this->getConnection(), $countStream, [
91
-			'bucket' => $this->bucket,
92
-			'key' => $urn,
93
-			'part_size' => $this->uploadPartSize,
94
-		]);
90
+        $uploader = new MultipartUploader($this->getConnection(), $countStream, [
91
+            'bucket' => $this->bucket,
92
+            'key' => $urn,
93
+            'part_size' => $this->uploadPartSize,
94
+        ]);
95 95
 
96
-		try {
97
-			$uploader->upload();
98
-		} catch (S3MultipartUploadException $e) {
99
-			// This is an empty file so just touch it then
100
-			if ($count === 0 && feof($countStream)) {
101
-				$uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '');
102
-				$uploader->upload();
103
-			} else {
104
-				throw $e;
105
-			}
106
-		}
96
+        try {
97
+            $uploader->upload();
98
+        } catch (S3MultipartUploadException $e) {
99
+            // This is an empty file so just touch it then
100
+            if ($count === 0 && feof($countStream)) {
101
+                $uploader = new ObjectUploader($this->getConnection(), $this->bucket, $urn, '');
102
+                $uploader->upload();
103
+            } else {
104
+                throw $e;
105
+            }
106
+        }
107 107
 
108
-		fclose($countStream);
109
-	}
108
+        fclose($countStream);
109
+    }
110 110
 
111
-	/**
112
-	 * @param string $urn the unified resource name used to identify the object
113
-	 * @return void
114
-	 * @throws \Exception when something goes wrong, message will be logged
115
-	 * @since 7.0.0
116
-	 */
117
-	public function deleteObject($urn) {
118
-		$this->getConnection()->deleteObject([
119
-			'Bucket' => $this->bucket,
120
-			'Key' => $urn,
121
-		]);
122
-	}
111
+    /**
112
+     * @param string $urn the unified resource name used to identify the object
113
+     * @return void
114
+     * @throws \Exception when something goes wrong, message will be logged
115
+     * @since 7.0.0
116
+     */
117
+    public function deleteObject($urn) {
118
+        $this->getConnection()->deleteObject([
119
+            'Bucket' => $this->bucket,
120
+            'Key' => $urn,
121
+        ]);
122
+    }
123 123
 
124
-	public function objectExists($urn) {
125
-		return $this->getConnection()->doesObjectExist($this->bucket, $urn);
126
-	}
124
+    public function objectExists($urn) {
125
+        return $this->getConnection()->doesObjectExist($this->bucket, $urn);
126
+    }
127 127
 
128
-	public function copyObject($from, $to) {
129
-		$this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to);
130
-	}
128
+    public function copyObject($from, $to) {
129
+        $this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to);
130
+    }
131 131
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/StorageObjectStore.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,70 +31,70 @@
 block discarded – undo
31 31
  * Object store that wraps a storage backend, mostly for testing purposes
32 32
  */
33 33
 class StorageObjectStore implements IObjectStore {
34
-	/** @var IStorage */
35
-	private $storage;
34
+    /** @var IStorage */
35
+    private $storage;
36 36
 
37
-	/**
38
-	 * @param IStorage $storage
39
-	 */
40
-	public function __construct(IStorage $storage) {
41
-		$this->storage = $storage;
42
-	}
37
+    /**
38
+     * @param IStorage $storage
39
+     */
40
+    public function __construct(IStorage $storage) {
41
+        $this->storage = $storage;
42
+    }
43 43
 
44
-	/**
45
-	 * @return string the container or bucket name where objects are stored
46
-	 * @since 7.0.0
47
-	 */
48
-	public function getStorageId() {
49
-		$this->storage->getId();
50
-	}
44
+    /**
45
+     * @return string the container or bucket name where objects are stored
46
+     * @since 7.0.0
47
+     */
48
+    public function getStorageId() {
49
+        $this->storage->getId();
50
+    }
51 51
 
52
-	/**
53
-	 * @param string $urn the unified resource name used to identify the object
54
-	 * @return resource stream with the read data
55
-	 * @throws \Exception when something goes wrong, message will be logged
56
-	 * @since 7.0.0
57
-	 */
58
-	public function readObject($urn) {
59
-		$handle = $this->storage->fopen($urn, 'r');
60
-		if ($handle) {
61
-			return $handle;
62
-		} else {
63
-			throw new \Exception();
64
-		}
65
-	}
52
+    /**
53
+     * @param string $urn the unified resource name used to identify the object
54
+     * @return resource stream with the read data
55
+     * @throws \Exception when something goes wrong, message will be logged
56
+     * @since 7.0.0
57
+     */
58
+    public function readObject($urn) {
59
+        $handle = $this->storage->fopen($urn, 'r');
60
+        if ($handle) {
61
+            return $handle;
62
+        } else {
63
+            throw new \Exception();
64
+        }
65
+    }
66 66
 
67
-	/**
68
-	 * @param string $urn the unified resource name used to identify the object
69
-	 * @param resource $stream stream with the data to write
70
-	 * @throws \Exception when something goes wrong, message will be logged
71
-	 * @since 7.0.0
72
-	 */
73
-	public function writeObject($urn, $stream) {
74
-		$handle = $this->storage->fopen($urn, 'w');
75
-		if ($handle) {
76
-			stream_copy_to_stream($stream, $handle);
77
-			fclose($handle);
78
-		} else {
79
-			throw new \Exception();
80
-		}
81
-	}
67
+    /**
68
+     * @param string $urn the unified resource name used to identify the object
69
+     * @param resource $stream stream with the data to write
70
+     * @throws \Exception when something goes wrong, message will be logged
71
+     * @since 7.0.0
72
+     */
73
+    public function writeObject($urn, $stream) {
74
+        $handle = $this->storage->fopen($urn, 'w');
75
+        if ($handle) {
76
+            stream_copy_to_stream($stream, $handle);
77
+            fclose($handle);
78
+        } else {
79
+            throw new \Exception();
80
+        }
81
+    }
82 82
 
83
-	/**
84
-	 * @param string $urn the unified resource name used to identify the object
85
-	 * @return void
86
-	 * @throws \Exception when something goes wrong, message will be logged
87
-	 * @since 7.0.0
88
-	 */
89
-	public function deleteObject($urn) {
90
-		$this->storage->unlink($urn);
91
-	}
83
+    /**
84
+     * @param string $urn the unified resource name used to identify the object
85
+     * @return void
86
+     * @throws \Exception when something goes wrong, message will be logged
87
+     * @since 7.0.0
88
+     */
89
+    public function deleteObject($urn) {
90
+        $this->storage->unlink($urn);
91
+    }
92 92
 
93
-	public function objectExists($urn) {
94
-		return $this->storage->file_exists($urn);
95
-	}
93
+    public function objectExists($urn) {
94
+        return $this->storage->file_exists($urn);
95
+    }
96 96
 
97
-	public function copyObject($from, $to) {
98
-		$this->storage->copy($from, $to);
99
-	}
97
+    public function copyObject($from, $to) {
98
+        $this->storage->copy($from, $to);
99
+    }
100 100
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/Azure.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -28,110 +28,110 @@
 block discarded – undo
28 28
 use OCP\Files\ObjectStore\IObjectStore;
29 29
 
30 30
 class Azure implements IObjectStore {
31
-	/** @var string */
32
-	private $containerName;
33
-	/** @var string */
34
-	private $accountName;
35
-	/** @var string */
36
-	private $accountKey;
37
-	/** @var BlobRestProxy|null */
38
-	private $blobClient = null;
39
-	/** @var string|null */
40
-	private $endpoint = null;
41
-	/** @var bool  */
42
-	private $autoCreate = false;
31
+    /** @var string */
32
+    private $containerName;
33
+    /** @var string */
34
+    private $accountName;
35
+    /** @var string */
36
+    private $accountKey;
37
+    /** @var BlobRestProxy|null */
38
+    private $blobClient = null;
39
+    /** @var string|null */
40
+    private $endpoint = null;
41
+    /** @var bool  */
42
+    private $autoCreate = false;
43 43
 
44
-	/**
45
-	 * @param array $parameters
46
-	 */
47
-	public function __construct($parameters) {
48
-		$this->containerName = $parameters['container'];
49
-		$this->accountName = $parameters['account_name'];
50
-		$this->accountKey = $parameters['account_key'];
51
-		if (isset($parameters['endpoint'])) {
52
-			$this->endpoint = $parameters['endpoint'];
53
-		}
54
-		if (isset($parameters['autocreate'])) {
55
-			$this->autoCreate = $parameters['autocreate'];
56
-		}
57
-	}
44
+    /**
45
+     * @param array $parameters
46
+     */
47
+    public function __construct($parameters) {
48
+        $this->containerName = $parameters['container'];
49
+        $this->accountName = $parameters['account_name'];
50
+        $this->accountKey = $parameters['account_key'];
51
+        if (isset($parameters['endpoint'])) {
52
+            $this->endpoint = $parameters['endpoint'];
53
+        }
54
+        if (isset($parameters['autocreate'])) {
55
+            $this->autoCreate = $parameters['autocreate'];
56
+        }
57
+    }
58 58
 
59
-	/**
60
-	 * @return BlobRestProxy
61
-	 */
62
-	private function getBlobClient() {
63
-		if (!$this->blobClient) {
64
-			$protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https';
65
-			$connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey;
66
-			if ($this->endpoint) {
67
-				$connectionString .= ';BlobEndpoint=' . $this->endpoint;
68
-			}
69
-			$this->blobClient = BlobRestProxy::createBlobService($connectionString);
59
+    /**
60
+     * @return BlobRestProxy
61
+     */
62
+    private function getBlobClient() {
63
+        if (!$this->blobClient) {
64
+            $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https';
65
+            $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey;
66
+            if ($this->endpoint) {
67
+                $connectionString .= ';BlobEndpoint=' . $this->endpoint;
68
+            }
69
+            $this->blobClient = BlobRestProxy::createBlobService($connectionString);
70 70
 
71
-			if ($this->autoCreate) {
72
-				try {
73
-					$this->blobClient->createContainer($this->containerName);
74
-				} catch (ServiceException $e) {
75
-					if ($e->getCode() === 409) {
76
-						// already exists
77
-					} else {
78
-						throw $e;
79
-					}
80
-				}
81
-			}
82
-		}
83
-		return $this->blobClient;
84
-	}
71
+            if ($this->autoCreate) {
72
+                try {
73
+                    $this->blobClient->createContainer($this->containerName);
74
+                } catch (ServiceException $e) {
75
+                    if ($e->getCode() === 409) {
76
+                        // already exists
77
+                    } else {
78
+                        throw $e;
79
+                    }
80
+                }
81
+            }
82
+        }
83
+        return $this->blobClient;
84
+    }
85 85
 
86
-	/**
87
-	 * @return string the container or bucket name where objects are stored
88
-	 */
89
-	public function getStorageId() {
90
-		return 'azure::blob::' . $this->containerName;
91
-	}
86
+    /**
87
+     * @return string the container or bucket name where objects are stored
88
+     */
89
+    public function getStorageId() {
90
+        return 'azure::blob::' . $this->containerName;
91
+    }
92 92
 
93
-	/**
94
-	 * @param string $urn the unified resource name used to identify the object
95
-	 * @return resource stream with the read data
96
-	 * @throws \Exception when something goes wrong, message will be logged
97
-	 */
98
-	public function readObject($urn) {
99
-		$blob = $this->getBlobClient()->getBlob($this->containerName, $urn);
100
-		return $blob->getContentStream();
101
-	}
93
+    /**
94
+     * @param string $urn the unified resource name used to identify the object
95
+     * @return resource stream with the read data
96
+     * @throws \Exception when something goes wrong, message will be logged
97
+     */
98
+    public function readObject($urn) {
99
+        $blob = $this->getBlobClient()->getBlob($this->containerName, $urn);
100
+        return $blob->getContentStream();
101
+    }
102 102
 
103
-	/**
104
-	 * @param string $urn the unified resource name used to identify the object
105
-	 * @param resource $stream stream with the data to write
106
-	 * @throws \Exception when something goes wrong, message will be logged
107
-	 */
108
-	public function writeObject($urn, $stream) {
109
-		$this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream);
110
-	}
103
+    /**
104
+     * @param string $urn the unified resource name used to identify the object
105
+     * @param resource $stream stream with the data to write
106
+     * @throws \Exception when something goes wrong, message will be logged
107
+     */
108
+    public function writeObject($urn, $stream) {
109
+        $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream);
110
+    }
111 111
 
112
-	/**
113
-	 * @param string $urn the unified resource name used to identify the object
114
-	 * @return void
115
-	 * @throws \Exception when something goes wrong, message will be logged
116
-	 */
117
-	public function deleteObject($urn) {
118
-		$this->getBlobClient()->deleteBlob($this->containerName, $urn);
119
-	}
112
+    /**
113
+     * @param string $urn the unified resource name used to identify the object
114
+     * @return void
115
+     * @throws \Exception when something goes wrong, message will be logged
116
+     */
117
+    public function deleteObject($urn) {
118
+        $this->getBlobClient()->deleteBlob($this->containerName, $urn);
119
+    }
120 120
 
121
-	public function objectExists($urn) {
122
-		try {
123
-			$this->getBlobClient()->getBlobMetadata($this->containerName, $urn);
124
-			return true;
125
-		} catch (ServiceException $e) {
126
-			if ($e->getCode() === 404) {
127
-				return false;
128
-			} else {
129
-				throw $e;
130
-			}
131
-		}
132
-	}
121
+    public function objectExists($urn) {
122
+        try {
123
+            $this->getBlobClient()->getBlobMetadata($this->containerName, $urn);
124
+            return true;
125
+        } catch (ServiceException $e) {
126
+            if ($e->getCode() === 404) {
127
+                return false;
128
+            } else {
129
+                throw $e;
130
+            }
131
+        }
132
+    }
133 133
 
134
-	public function copyObject($from, $to) {
135
-		$this->getBlobClient()->copyBlob($this->containerName, $to, $this->containerName, $from);
136
-	}
134
+    public function copyObject($from, $to) {
135
+        $this->getBlobClient()->copyBlob($this->containerName, $to, $this->containerName, $from);
136
+    }
137 137
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/ObjectStoreStorage.php 2 patches
Indentation   +540 added lines, -540 removed lines patch added patch discarded remove patch
@@ -40,547 +40,547 @@
 block discarded – undo
40 40
 use OCP\Files\ObjectStore\IObjectStore;
41 41
 
42 42
 class ObjectStoreStorage extends \OC\Files\Storage\Common {
43
-	use CopyDirectory;
44
-
45
-	/**
46
-	 * @var \OCP\Files\ObjectStore\IObjectStore $objectStore
47
-	 */
48
-	protected $objectStore;
49
-	/**
50
-	 * @var string $id
51
-	 */
52
-	protected $id;
53
-	/**
54
-	 * @var \OC\User\User $user
55
-	 */
56
-	protected $user;
57
-
58
-	private $objectPrefix = 'urn:oid:';
59
-
60
-	private $logger;
61
-
62
-	public function __construct($params) {
63
-		if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
64
-			$this->objectStore = $params['objectstore'];
65
-		} else {
66
-			throw new \Exception('missing IObjectStore instance');
67
-		}
68
-		if (isset($params['storageid'])) {
69
-			$this->id = 'object::store:' . $params['storageid'];
70
-		} else {
71
-			$this->id = 'object::store:' . $this->objectStore->getStorageId();
72
-		}
73
-		if (isset($params['objectPrefix'])) {
74
-			$this->objectPrefix = $params['objectPrefix'];
75
-		}
76
-		//initialize cache with root directory in cache
77
-		if (!$this->is_dir('/')) {
78
-			$this->mkdir('/');
79
-		}
80
-
81
-		$this->logger = \OC::$server->getLogger();
82
-	}
83
-
84
-	public function mkdir($path) {
85
-		$path = $this->normalizePath($path);
86
-
87
-		if ($this->file_exists($path)) {
88
-			return false;
89
-		}
90
-
91
-		$mTime = time();
92
-		$data = [
93
-			'mimetype' => 'httpd/unix-directory',
94
-			'size' => 0,
95
-			'mtime' => $mTime,
96
-			'storage_mtime' => $mTime,
97
-			'permissions' => \OCP\Constants::PERMISSION_ALL,
98
-		];
99
-		if ($path === '') {
100
-			//create root on the fly
101
-			$data['etag'] = $this->getETag('');
102
-			$this->getCache()->put('', $data);
103
-			return true;
104
-		} else {
105
-			// if parent does not exist, create it
106
-			$parent = $this->normalizePath(dirname($path));
107
-			$parentType = $this->filetype($parent);
108
-			if ($parentType === false) {
109
-				if (!$this->mkdir($parent)) {
110
-					// something went wrong
111
-					return false;
112
-				}
113
-			} elseif ($parentType === 'file') {
114
-				// parent is a file
115
-				return false;
116
-			}
117
-			// finally create the new dir
118
-			$mTime = time(); // update mtime
119
-			$data['mtime'] = $mTime;
120
-			$data['storage_mtime'] = $mTime;
121
-			$data['etag'] = $this->getETag($path);
122
-			$this->getCache()->put($path, $data);
123
-			return true;
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * @param string $path
129
-	 * @return string
130
-	 */
131
-	private function normalizePath($path) {
132
-		$path = trim($path, '/');
133
-		//FIXME why do we sometimes get a path like 'files//username'?
134
-		$path = str_replace('//', '/', $path);
135
-
136
-		// dirname('/folder') returns '.' but internally (in the cache) we store the root as ''
137
-		if (!$path || $path === '.') {
138
-			$path = '';
139
-		}
140
-
141
-		return $path;
142
-	}
143
-
144
-	/**
145
-	 * Object Stores use a NoopScanner because metadata is directly stored in
146
-	 * the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere.
147
-	 *
148
-	 * @param string $path
149
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
150
-	 * @return \OC\Files\ObjectStore\NoopScanner
151
-	 */
152
-	public function getScanner($path = '', $storage = null) {
153
-		if (!$storage) {
154
-			$storage = $this;
155
-		}
156
-		if (!isset($this->scanner)) {
157
-			$this->scanner = new NoopScanner($storage);
158
-		}
159
-		return $this->scanner;
160
-	}
161
-
162
-	public function getId() {
163
-		return $this->id;
164
-	}
165
-
166
-	public function rmdir($path) {
167
-		$path = $this->normalizePath($path);
168
-
169
-		if (!$this->is_dir($path)) {
170
-			return false;
171
-		}
172
-
173
-		if (!$this->rmObjects($path)) {
174
-			return false;
175
-		}
176
-
177
-		$this->getCache()->remove($path);
178
-
179
-		return true;
180
-	}
181
-
182
-	private function rmObjects($path) {
183
-		$children = $this->getCache()->getFolderContents($path);
184
-		foreach ($children as $child) {
185
-			if ($child['mimetype'] === 'httpd/unix-directory') {
186
-				if (!$this->rmObjects($child['path'])) {
187
-					return false;
188
-				}
189
-			} else {
190
-				if (!$this->unlink($child['path'])) {
191
-					return false;
192
-				}
193
-			}
194
-		}
195
-
196
-		return true;
197
-	}
198
-
199
-	public function unlink($path) {
200
-		$path = $this->normalizePath($path);
201
-		$stat = $this->stat($path);
202
-
203
-		if ($stat && isset($stat['fileid'])) {
204
-			if ($stat['mimetype'] === 'httpd/unix-directory') {
205
-				return $this->rmdir($path);
206
-			}
207
-			try {
208
-				$this->objectStore->deleteObject($this->getURN($stat['fileid']));
209
-			} catch (\Exception $ex) {
210
-				if ($ex->getCode() !== 404) {
211
-					$this->logger->logException($ex, [
212
-						'app' => 'objectstore',
213
-						'message' => 'Could not delete object ' . $this->getURN($stat['fileid']) . ' for ' . $path,
214
-					]);
215
-					return false;
216
-				}
217
-				//removing from cache is ok as it does not exist in the objectstore anyway
218
-			}
219
-			$this->getCache()->remove($path);
220
-			return true;
221
-		}
222
-		return false;
223
-	}
224
-
225
-	public function stat($path) {
226
-		$path = $this->normalizePath($path);
227
-		$cacheEntry = $this->getCache()->get($path);
228
-		if ($cacheEntry instanceof CacheEntry) {
229
-			return $cacheEntry->getData();
230
-		} else {
231
-			return false;
232
-		}
233
-	}
234
-
235
-	public function getPermissions($path) {
236
-		$stat = $this->stat($path);
237
-
238
-		if (is_array($stat) && isset($stat['permissions'])) {
239
-			return $stat['permissions'];
240
-		}
241
-
242
-		return parent::getPermissions($path);
243
-	}
244
-
245
-	/**
246
-	 * Override this method if you need a different unique resource identifier for your object storage implementation.
247
-	 * The default implementations just appends the fileId to 'urn:oid:'. Make sure the URN is unique over all users.
248
-	 * You may need a mapping table to store your URN if it cannot be generated from the fileid.
249
-	 *
250
-	 * @param int $fileId the fileid
251
-	 * @return null|string the unified resource name used to identify the object
252
-	 */
253
-	public function getURN($fileId) {
254
-		if (is_numeric($fileId)) {
255
-			return $this->objectPrefix . $fileId;
256
-		}
257
-		return null;
258
-	}
259
-
260
-	public function opendir($path) {
261
-		$path = $this->normalizePath($path);
262
-
263
-		try {
264
-			$files = [];
265
-			$folderContents = $this->getCache()->getFolderContents($path);
266
-			foreach ($folderContents as $file) {
267
-				$files[] = $file['name'];
268
-			}
269
-
270
-			return IteratorDirectory::wrap($files);
271
-		} catch (\Exception $e) {
272
-			$this->logger->logException($e);
273
-			return false;
274
-		}
275
-	}
276
-
277
-	public function filetype($path) {
278
-		$path = $this->normalizePath($path);
279
-		$stat = $this->stat($path);
280
-		if ($stat) {
281
-			if ($stat['mimetype'] === 'httpd/unix-directory') {
282
-				return 'dir';
283
-			}
284
-			return 'file';
285
-		} else {
286
-			return false;
287
-		}
288
-	}
289
-
290
-	public function fopen($path, $mode) {
291
-		$path = $this->normalizePath($path);
292
-
293
-		if (strrpos($path, '.') !== false) {
294
-			$ext = substr($path, strrpos($path, '.'));
295
-		} else {
296
-			$ext = '';
297
-		}
298
-
299
-		switch ($mode) {
300
-			case 'r':
301
-			case 'rb':
302
-				$stat = $this->stat($path);
303
-				if (is_array($stat)) {
304
-					// Reading 0 sized files is a waste of time
305
-					if (isset($stat['size']) && $stat['size'] === 0) {
306
-						return fopen('php://memory', $mode);
307
-					}
308
-
309
-					try {
310
-						return $this->objectStore->readObject($this->getURN($stat['fileid']));
311
-					} catch (NotFoundException $e) {
312
-						$this->logger->logException($e, [
313
-							'app' => 'objectstore',
314
-							'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
315
-						]);
316
-						throw $e;
317
-					} catch (\Exception $ex) {
318
-						$this->logger->logException($ex, [
319
-							'app' => 'objectstore',
320
-							'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
321
-						]);
322
-						return false;
323
-					}
324
-				} else {
325
-					return false;
326
-				}
327
-			// no break
328
-			case 'w':
329
-			case 'wb':
330
-			case 'w+':
331
-			case 'wb+':
332
-				$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
333
-				$handle = fopen($tmpFile, $mode);
334
-				return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
335
-					$this->writeBack($tmpFile, $path);
336
-				});
337
-			case 'a':
338
-			case 'ab':
339
-			case 'r+':
340
-			case 'a+':
341
-			case 'x':
342
-			case 'x+':
343
-			case 'c':
344
-			case 'c+':
345
-				$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
346
-				if ($this->file_exists($path)) {
347
-					$source = $this->fopen($path, 'r');
348
-					file_put_contents($tmpFile, $source);
349
-				}
350
-				$handle = fopen($tmpFile, $mode);
351
-				return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
352
-					$this->writeBack($tmpFile, $path);
353
-				});
354
-		}
355
-		return false;
356
-	}
357
-
358
-	public function file_exists($path) {
359
-		$path = $this->normalizePath($path);
360
-		return (bool)$this->stat($path);
361
-	}
362
-
363
-	public function rename($source, $target) {
364
-		$source = $this->normalizePath($source);
365
-		$target = $this->normalizePath($target);
366
-		$this->remove($target);
367
-		$this->getCache()->move($source, $target);
368
-		$this->touch(dirname($target));
369
-		return true;
370
-	}
371
-
372
-	public function getMimeType($path) {
373
-		$path = $this->normalizePath($path);
374
-		return parent::getMimeType($path);
375
-	}
376
-
377
-	public function touch($path, $mtime = null) {
378
-		if (is_null($mtime)) {
379
-			$mtime = time();
380
-		}
381
-
382
-		$path = $this->normalizePath($path);
383
-		$dirName = dirname($path);
384
-		$parentExists = $this->is_dir($dirName);
385
-		if (!$parentExists) {
386
-			return false;
387
-		}
388
-
389
-		$stat = $this->stat($path);
390
-		if (is_array($stat)) {
391
-			// update existing mtime in db
392
-			$stat['mtime'] = $mtime;
393
-			$this->getCache()->update($stat['fileid'], $stat);
394
-		} else {
395
-			try {
396
-				//create a empty file, need to have at least on char to make it
397
-				// work with all object storage implementations
398
-				$this->file_put_contents($path, ' ');
399
-				$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
400
-				$stat = [
401
-					'etag' => $this->getETag($path),
402
-					'mimetype' => $mimeType,
403
-					'size' => 0,
404
-					'mtime' => $mtime,
405
-					'storage_mtime' => $mtime,
406
-					'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
407
-				];
408
-				$this->getCache()->put($path, $stat);
409
-			} catch (\Exception $ex) {
410
-				$this->logger->logException($ex, [
411
-					'app' => 'objectstore',
412
-					'message' => 'Could not create object for ' . $path,
413
-				]);
414
-				throw $ex;
415
-			}
416
-		}
417
-		return true;
418
-	}
419
-
420
-	public function writeBack($tmpFile, $path) {
421
-		$size = filesize($tmpFile);
422
-		$this->writeStream($path, fopen($tmpFile, 'r'), $size);
423
-	}
424
-
425
-	/**
426
-	 * external changes are not supported, exclusive access to the object storage is assumed
427
-	 *
428
-	 * @param string $path
429
-	 * @param int $time
430
-	 * @return false
431
-	 */
432
-	public function hasUpdated($path, $time) {
433
-		return false;
434
-	}
435
-
436
-	public function needsPartFile() {
437
-		return false;
438
-	}
439
-
440
-	public function file_put_contents($path, $data) {
441
-		$handle = $this->fopen($path, 'w+');
442
-		fwrite($handle, $data);
443
-		fclose($handle);
444
-		return true;
445
-	}
446
-
447
-	public function writeStream(string $path, $stream, int $size = null): int {
448
-		$stat = $this->stat($path);
449
-		if (empty($stat)) {
450
-			// create new file
451
-			$stat = [
452
-				'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
453
-			];
454
-		}
455
-		// update stat with new data
456
-		$mTime = time();
457
-		$stat['size'] = (int)$size;
458
-		$stat['mtime'] = $mTime;
459
-		$stat['storage_mtime'] = $mTime;
460
-
461
-		$mimetypeDetector = \OC::$server->getMimeTypeDetector();
462
-		$mimetype = $mimetypeDetector->detectPath($path);
463
-
464
-		$stat['mimetype'] = $mimetype;
465
-		$stat['etag'] = $this->getETag($path);
466
-
467
-		$exists = $this->getCache()->inCache($path);
468
-		$uploadPath = $exists ? $path : $path . '.part';
469
-
470
-		if ($exists) {
471
-			$fileId = $stat['fileid'];
472
-		} else {
473
-			$fileId = $this->getCache()->put($uploadPath, $stat);
474
-		}
475
-
476
-		$urn = $this->getURN($fileId);
477
-		try {
478
-			//upload to object storage
479
-			if ($size === null) {
480
-				$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {
481
-					$this->getCache()->update($fileId, [
482
-						'size' => $writtenSize,
483
-					]);
484
-					$size = $writtenSize;
485
-				});
486
-				$this->objectStore->writeObject($urn, $countStream);
487
-				if (is_resource($countStream)) {
488
-					fclose($countStream);
489
-				}
490
-				$stat['size'] = $size;
491
-			} else {
492
-				$this->objectStore->writeObject($urn, $stream);
493
-			}
494
-		} catch (\Exception $ex) {
495
-			if (!$exists) {
496
-				/*
43
+    use CopyDirectory;
44
+
45
+    /**
46
+     * @var \OCP\Files\ObjectStore\IObjectStore $objectStore
47
+     */
48
+    protected $objectStore;
49
+    /**
50
+     * @var string $id
51
+     */
52
+    protected $id;
53
+    /**
54
+     * @var \OC\User\User $user
55
+     */
56
+    protected $user;
57
+
58
+    private $objectPrefix = 'urn:oid:';
59
+
60
+    private $logger;
61
+
62
+    public function __construct($params) {
63
+        if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
64
+            $this->objectStore = $params['objectstore'];
65
+        } else {
66
+            throw new \Exception('missing IObjectStore instance');
67
+        }
68
+        if (isset($params['storageid'])) {
69
+            $this->id = 'object::store:' . $params['storageid'];
70
+        } else {
71
+            $this->id = 'object::store:' . $this->objectStore->getStorageId();
72
+        }
73
+        if (isset($params['objectPrefix'])) {
74
+            $this->objectPrefix = $params['objectPrefix'];
75
+        }
76
+        //initialize cache with root directory in cache
77
+        if (!$this->is_dir('/')) {
78
+            $this->mkdir('/');
79
+        }
80
+
81
+        $this->logger = \OC::$server->getLogger();
82
+    }
83
+
84
+    public function mkdir($path) {
85
+        $path = $this->normalizePath($path);
86
+
87
+        if ($this->file_exists($path)) {
88
+            return false;
89
+        }
90
+
91
+        $mTime = time();
92
+        $data = [
93
+            'mimetype' => 'httpd/unix-directory',
94
+            'size' => 0,
95
+            'mtime' => $mTime,
96
+            'storage_mtime' => $mTime,
97
+            'permissions' => \OCP\Constants::PERMISSION_ALL,
98
+        ];
99
+        if ($path === '') {
100
+            //create root on the fly
101
+            $data['etag'] = $this->getETag('');
102
+            $this->getCache()->put('', $data);
103
+            return true;
104
+        } else {
105
+            // if parent does not exist, create it
106
+            $parent = $this->normalizePath(dirname($path));
107
+            $parentType = $this->filetype($parent);
108
+            if ($parentType === false) {
109
+                if (!$this->mkdir($parent)) {
110
+                    // something went wrong
111
+                    return false;
112
+                }
113
+            } elseif ($parentType === 'file') {
114
+                // parent is a file
115
+                return false;
116
+            }
117
+            // finally create the new dir
118
+            $mTime = time(); // update mtime
119
+            $data['mtime'] = $mTime;
120
+            $data['storage_mtime'] = $mTime;
121
+            $data['etag'] = $this->getETag($path);
122
+            $this->getCache()->put($path, $data);
123
+            return true;
124
+        }
125
+    }
126
+
127
+    /**
128
+     * @param string $path
129
+     * @return string
130
+     */
131
+    private function normalizePath($path) {
132
+        $path = trim($path, '/');
133
+        //FIXME why do we sometimes get a path like 'files//username'?
134
+        $path = str_replace('//', '/', $path);
135
+
136
+        // dirname('/folder') returns '.' but internally (in the cache) we store the root as ''
137
+        if (!$path || $path === '.') {
138
+            $path = '';
139
+        }
140
+
141
+        return $path;
142
+    }
143
+
144
+    /**
145
+     * Object Stores use a NoopScanner because metadata is directly stored in
146
+     * the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere.
147
+     *
148
+     * @param string $path
149
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
150
+     * @return \OC\Files\ObjectStore\NoopScanner
151
+     */
152
+    public function getScanner($path = '', $storage = null) {
153
+        if (!$storage) {
154
+            $storage = $this;
155
+        }
156
+        if (!isset($this->scanner)) {
157
+            $this->scanner = new NoopScanner($storage);
158
+        }
159
+        return $this->scanner;
160
+    }
161
+
162
+    public function getId() {
163
+        return $this->id;
164
+    }
165
+
166
+    public function rmdir($path) {
167
+        $path = $this->normalizePath($path);
168
+
169
+        if (!$this->is_dir($path)) {
170
+            return false;
171
+        }
172
+
173
+        if (!$this->rmObjects($path)) {
174
+            return false;
175
+        }
176
+
177
+        $this->getCache()->remove($path);
178
+
179
+        return true;
180
+    }
181
+
182
+    private function rmObjects($path) {
183
+        $children = $this->getCache()->getFolderContents($path);
184
+        foreach ($children as $child) {
185
+            if ($child['mimetype'] === 'httpd/unix-directory') {
186
+                if (!$this->rmObjects($child['path'])) {
187
+                    return false;
188
+                }
189
+            } else {
190
+                if (!$this->unlink($child['path'])) {
191
+                    return false;
192
+                }
193
+            }
194
+        }
195
+
196
+        return true;
197
+    }
198
+
199
+    public function unlink($path) {
200
+        $path = $this->normalizePath($path);
201
+        $stat = $this->stat($path);
202
+
203
+        if ($stat && isset($stat['fileid'])) {
204
+            if ($stat['mimetype'] === 'httpd/unix-directory') {
205
+                return $this->rmdir($path);
206
+            }
207
+            try {
208
+                $this->objectStore->deleteObject($this->getURN($stat['fileid']));
209
+            } catch (\Exception $ex) {
210
+                if ($ex->getCode() !== 404) {
211
+                    $this->logger->logException($ex, [
212
+                        'app' => 'objectstore',
213
+                        'message' => 'Could not delete object ' . $this->getURN($stat['fileid']) . ' for ' . $path,
214
+                    ]);
215
+                    return false;
216
+                }
217
+                //removing from cache is ok as it does not exist in the objectstore anyway
218
+            }
219
+            $this->getCache()->remove($path);
220
+            return true;
221
+        }
222
+        return false;
223
+    }
224
+
225
+    public function stat($path) {
226
+        $path = $this->normalizePath($path);
227
+        $cacheEntry = $this->getCache()->get($path);
228
+        if ($cacheEntry instanceof CacheEntry) {
229
+            return $cacheEntry->getData();
230
+        } else {
231
+            return false;
232
+        }
233
+    }
234
+
235
+    public function getPermissions($path) {
236
+        $stat = $this->stat($path);
237
+
238
+        if (is_array($stat) && isset($stat['permissions'])) {
239
+            return $stat['permissions'];
240
+        }
241
+
242
+        return parent::getPermissions($path);
243
+    }
244
+
245
+    /**
246
+     * Override this method if you need a different unique resource identifier for your object storage implementation.
247
+     * The default implementations just appends the fileId to 'urn:oid:'. Make sure the URN is unique over all users.
248
+     * You may need a mapping table to store your URN if it cannot be generated from the fileid.
249
+     *
250
+     * @param int $fileId the fileid
251
+     * @return null|string the unified resource name used to identify the object
252
+     */
253
+    public function getURN($fileId) {
254
+        if (is_numeric($fileId)) {
255
+            return $this->objectPrefix . $fileId;
256
+        }
257
+        return null;
258
+    }
259
+
260
+    public function opendir($path) {
261
+        $path = $this->normalizePath($path);
262
+
263
+        try {
264
+            $files = [];
265
+            $folderContents = $this->getCache()->getFolderContents($path);
266
+            foreach ($folderContents as $file) {
267
+                $files[] = $file['name'];
268
+            }
269
+
270
+            return IteratorDirectory::wrap($files);
271
+        } catch (\Exception $e) {
272
+            $this->logger->logException($e);
273
+            return false;
274
+        }
275
+    }
276
+
277
+    public function filetype($path) {
278
+        $path = $this->normalizePath($path);
279
+        $stat = $this->stat($path);
280
+        if ($stat) {
281
+            if ($stat['mimetype'] === 'httpd/unix-directory') {
282
+                return 'dir';
283
+            }
284
+            return 'file';
285
+        } else {
286
+            return false;
287
+        }
288
+    }
289
+
290
+    public function fopen($path, $mode) {
291
+        $path = $this->normalizePath($path);
292
+
293
+        if (strrpos($path, '.') !== false) {
294
+            $ext = substr($path, strrpos($path, '.'));
295
+        } else {
296
+            $ext = '';
297
+        }
298
+
299
+        switch ($mode) {
300
+            case 'r':
301
+            case 'rb':
302
+                $stat = $this->stat($path);
303
+                if (is_array($stat)) {
304
+                    // Reading 0 sized files is a waste of time
305
+                    if (isset($stat['size']) && $stat['size'] === 0) {
306
+                        return fopen('php://memory', $mode);
307
+                    }
308
+
309
+                    try {
310
+                        return $this->objectStore->readObject($this->getURN($stat['fileid']));
311
+                    } catch (NotFoundException $e) {
312
+                        $this->logger->logException($e, [
313
+                            'app' => 'objectstore',
314
+                            'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
315
+                        ]);
316
+                        throw $e;
317
+                    } catch (\Exception $ex) {
318
+                        $this->logger->logException($ex, [
319
+                            'app' => 'objectstore',
320
+                            'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
321
+                        ]);
322
+                        return false;
323
+                    }
324
+                } else {
325
+                    return false;
326
+                }
327
+            // no break
328
+            case 'w':
329
+            case 'wb':
330
+            case 'w+':
331
+            case 'wb+':
332
+                $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
333
+                $handle = fopen($tmpFile, $mode);
334
+                return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
335
+                    $this->writeBack($tmpFile, $path);
336
+                });
337
+            case 'a':
338
+            case 'ab':
339
+            case 'r+':
340
+            case 'a+':
341
+            case 'x':
342
+            case 'x+':
343
+            case 'c':
344
+            case 'c+':
345
+                $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
346
+                if ($this->file_exists($path)) {
347
+                    $source = $this->fopen($path, 'r');
348
+                    file_put_contents($tmpFile, $source);
349
+                }
350
+                $handle = fopen($tmpFile, $mode);
351
+                return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
352
+                    $this->writeBack($tmpFile, $path);
353
+                });
354
+        }
355
+        return false;
356
+    }
357
+
358
+    public function file_exists($path) {
359
+        $path = $this->normalizePath($path);
360
+        return (bool)$this->stat($path);
361
+    }
362
+
363
+    public function rename($source, $target) {
364
+        $source = $this->normalizePath($source);
365
+        $target = $this->normalizePath($target);
366
+        $this->remove($target);
367
+        $this->getCache()->move($source, $target);
368
+        $this->touch(dirname($target));
369
+        return true;
370
+    }
371
+
372
+    public function getMimeType($path) {
373
+        $path = $this->normalizePath($path);
374
+        return parent::getMimeType($path);
375
+    }
376
+
377
+    public function touch($path, $mtime = null) {
378
+        if (is_null($mtime)) {
379
+            $mtime = time();
380
+        }
381
+
382
+        $path = $this->normalizePath($path);
383
+        $dirName = dirname($path);
384
+        $parentExists = $this->is_dir($dirName);
385
+        if (!$parentExists) {
386
+            return false;
387
+        }
388
+
389
+        $stat = $this->stat($path);
390
+        if (is_array($stat)) {
391
+            // update existing mtime in db
392
+            $stat['mtime'] = $mtime;
393
+            $this->getCache()->update($stat['fileid'], $stat);
394
+        } else {
395
+            try {
396
+                //create a empty file, need to have at least on char to make it
397
+                // work with all object storage implementations
398
+                $this->file_put_contents($path, ' ');
399
+                $mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
400
+                $stat = [
401
+                    'etag' => $this->getETag($path),
402
+                    'mimetype' => $mimeType,
403
+                    'size' => 0,
404
+                    'mtime' => $mtime,
405
+                    'storage_mtime' => $mtime,
406
+                    'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
407
+                ];
408
+                $this->getCache()->put($path, $stat);
409
+            } catch (\Exception $ex) {
410
+                $this->logger->logException($ex, [
411
+                    'app' => 'objectstore',
412
+                    'message' => 'Could not create object for ' . $path,
413
+                ]);
414
+                throw $ex;
415
+            }
416
+        }
417
+        return true;
418
+    }
419
+
420
+    public function writeBack($tmpFile, $path) {
421
+        $size = filesize($tmpFile);
422
+        $this->writeStream($path, fopen($tmpFile, 'r'), $size);
423
+    }
424
+
425
+    /**
426
+     * external changes are not supported, exclusive access to the object storage is assumed
427
+     *
428
+     * @param string $path
429
+     * @param int $time
430
+     * @return false
431
+     */
432
+    public function hasUpdated($path, $time) {
433
+        return false;
434
+    }
435
+
436
+    public function needsPartFile() {
437
+        return false;
438
+    }
439
+
440
+    public function file_put_contents($path, $data) {
441
+        $handle = $this->fopen($path, 'w+');
442
+        fwrite($handle, $data);
443
+        fclose($handle);
444
+        return true;
445
+    }
446
+
447
+    public function writeStream(string $path, $stream, int $size = null): int {
448
+        $stat = $this->stat($path);
449
+        if (empty($stat)) {
450
+            // create new file
451
+            $stat = [
452
+                'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
453
+            ];
454
+        }
455
+        // update stat with new data
456
+        $mTime = time();
457
+        $stat['size'] = (int)$size;
458
+        $stat['mtime'] = $mTime;
459
+        $stat['storage_mtime'] = $mTime;
460
+
461
+        $mimetypeDetector = \OC::$server->getMimeTypeDetector();
462
+        $mimetype = $mimetypeDetector->detectPath($path);
463
+
464
+        $stat['mimetype'] = $mimetype;
465
+        $stat['etag'] = $this->getETag($path);
466
+
467
+        $exists = $this->getCache()->inCache($path);
468
+        $uploadPath = $exists ? $path : $path . '.part';
469
+
470
+        if ($exists) {
471
+            $fileId = $stat['fileid'];
472
+        } else {
473
+            $fileId = $this->getCache()->put($uploadPath, $stat);
474
+        }
475
+
476
+        $urn = $this->getURN($fileId);
477
+        try {
478
+            //upload to object storage
479
+            if ($size === null) {
480
+                $countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {
481
+                    $this->getCache()->update($fileId, [
482
+                        'size' => $writtenSize,
483
+                    ]);
484
+                    $size = $writtenSize;
485
+                });
486
+                $this->objectStore->writeObject($urn, $countStream);
487
+                if (is_resource($countStream)) {
488
+                    fclose($countStream);
489
+                }
490
+                $stat['size'] = $size;
491
+            } else {
492
+                $this->objectStore->writeObject($urn, $stream);
493
+            }
494
+        } catch (\Exception $ex) {
495
+            if (!$exists) {
496
+                /*
497 497
 				 * Only remove the entry if we are dealing with a new file.
498 498
 				 * Else people lose access to existing files
499 499
 				 */
500
-				$this->getCache()->remove($uploadPath);
501
-				$this->logger->logException($ex, [
502
-					'app' => 'objectstore',
503
-					'message' => 'Could not create object ' . $urn . ' for ' . $path,
504
-				]);
505
-			} else {
506
-				$this->logger->logException($ex, [
507
-					'app' => 'objectstore',
508
-					'message' => 'Could not update object ' . $urn . ' for ' . $path,
509
-				]);
510
-			}
511
-			throw $ex; // make this bubble up
512
-		}
513
-
514
-		if ($exists) {
515
-			$this->getCache()->update($fileId, $stat);
516
-		} else {
517
-			if ($this->objectStore->objectExists($urn)) {
518
-				$this->getCache()->move($uploadPath, $path);
519
-			} else {
520
-				$this->getCache()->remove($uploadPath);
521
-				throw new \Exception("Object not found after writing (urn: $urn, path: $path)", 404);
522
-			}
523
-		}
524
-
525
-		return $size;
526
-	}
527
-
528
-	public function getObjectStore(): IObjectStore {
529
-		return $this->objectStore;
530
-	}
531
-
532
-	public function copy($path1, $path2) {
533
-		$path1 = $this->normalizePath($path1);
534
-		$path2 = $this->normalizePath($path2);
535
-
536
-		$cache = $this->getCache();
537
-		$sourceEntry = $cache->get($path1);
538
-		if (!$sourceEntry) {
539
-			throw new NotFoundException('Source object not found');
540
-		}
541
-
542
-		$this->copyInner($sourceEntry, $path2);
543
-
544
-		return true;
545
-	}
546
-
547
-	private function copyInner(ICacheEntry $sourceEntry, string $to) {
548
-		$cache = $this->getCache();
549
-
550
-		if ($sourceEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
551
-			if ($cache->inCache($to)) {
552
-				$cache->remove($to);
553
-			}
554
-			$this->mkdir($to);
555
-
556
-			foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) {
557
-				$this->copyInner($child, $to . '/' . $child->getName());
558
-			}
559
-		} else {
560
-			$this->copyFile($sourceEntry, $to);
561
-		}
562
-	}
563
-
564
-	private function copyFile(ICacheEntry $sourceEntry, string $to) {
565
-		$cache = $this->getCache();
566
-
567
-		$sourceUrn = $this->getURN($sourceEntry->getId());
568
-
569
-		$cache->copyFromCache($cache, $sourceEntry, $to);
570
-		$targetEntry = $cache->get($to);
571
-
572
-		if (!$targetEntry) {
573
-			throw new \Exception('Target not in cache after copy');
574
-		}
575
-
576
-		$targetUrn = $this->getURN($targetEntry->getId());
577
-
578
-		try {
579
-			$this->objectStore->copyObject($sourceUrn, $targetUrn);
580
-		} catch (\Exception $e) {
581
-			$cache->remove($to);
582
-
583
-			throw $e;
584
-		}
585
-	}
500
+                $this->getCache()->remove($uploadPath);
501
+                $this->logger->logException($ex, [
502
+                    'app' => 'objectstore',
503
+                    'message' => 'Could not create object ' . $urn . ' for ' . $path,
504
+                ]);
505
+            } else {
506
+                $this->logger->logException($ex, [
507
+                    'app' => 'objectstore',
508
+                    'message' => 'Could not update object ' . $urn . ' for ' . $path,
509
+                ]);
510
+            }
511
+            throw $ex; // make this bubble up
512
+        }
513
+
514
+        if ($exists) {
515
+            $this->getCache()->update($fileId, $stat);
516
+        } else {
517
+            if ($this->objectStore->objectExists($urn)) {
518
+                $this->getCache()->move($uploadPath, $path);
519
+            } else {
520
+                $this->getCache()->remove($uploadPath);
521
+                throw new \Exception("Object not found after writing (urn: $urn, path: $path)", 404);
522
+            }
523
+        }
524
+
525
+        return $size;
526
+    }
527
+
528
+    public function getObjectStore(): IObjectStore {
529
+        return $this->objectStore;
530
+    }
531
+
532
+    public function copy($path1, $path2) {
533
+        $path1 = $this->normalizePath($path1);
534
+        $path2 = $this->normalizePath($path2);
535
+
536
+        $cache = $this->getCache();
537
+        $sourceEntry = $cache->get($path1);
538
+        if (!$sourceEntry) {
539
+            throw new NotFoundException('Source object not found');
540
+        }
541
+
542
+        $this->copyInner($sourceEntry, $path2);
543
+
544
+        return true;
545
+    }
546
+
547
+    private function copyInner(ICacheEntry $sourceEntry, string $to) {
548
+        $cache = $this->getCache();
549
+
550
+        if ($sourceEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
551
+            if ($cache->inCache($to)) {
552
+                $cache->remove($to);
553
+            }
554
+            $this->mkdir($to);
555
+
556
+            foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) {
557
+                $this->copyInner($child, $to . '/' . $child->getName());
558
+            }
559
+        } else {
560
+            $this->copyFile($sourceEntry, $to);
561
+        }
562
+    }
563
+
564
+    private function copyFile(ICacheEntry $sourceEntry, string $to) {
565
+        $cache = $this->getCache();
566
+
567
+        $sourceUrn = $this->getURN($sourceEntry->getId());
568
+
569
+        $cache->copyFromCache($cache, $sourceEntry, $to);
570
+        $targetEntry = $cache->get($to);
571
+
572
+        if (!$targetEntry) {
573
+            throw new \Exception('Target not in cache after copy');
574
+        }
575
+
576
+        $targetUrn = $this->getURN($targetEntry->getId());
577
+
578
+        try {
579
+            $this->objectStore->copyObject($sourceUrn, $targetUrn);
580
+        } catch (\Exception $e) {
581
+            $cache->remove($to);
582
+
583
+            throw $e;
584
+        }
585
+    }
586 586
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 			throw new \Exception('missing IObjectStore instance');
67 67
 		}
68 68
 		if (isset($params['storageid'])) {
69
-			$this->id = 'object::store:' . $params['storageid'];
69
+			$this->id = 'object::store:'.$params['storageid'];
70 70
 		} else {
71
-			$this->id = 'object::store:' . $this->objectStore->getStorageId();
71
+			$this->id = 'object::store:'.$this->objectStore->getStorageId();
72 72
 		}
73 73
 		if (isset($params['objectPrefix'])) {
74 74
 			$this->objectPrefix = $params['objectPrefix'];
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 				if ($ex->getCode() !== 404) {
211 211
 					$this->logger->logException($ex, [
212 212
 						'app' => 'objectstore',
213
-						'message' => 'Could not delete object ' . $this->getURN($stat['fileid']) . ' for ' . $path,
213
+						'message' => 'Could not delete object '.$this->getURN($stat['fileid']).' for '.$path,
214 214
 					]);
215 215
 					return false;
216 216
 				}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 */
253 253
 	public function getURN($fileId) {
254 254
 		if (is_numeric($fileId)) {
255
-			return $this->objectPrefix . $fileId;
255
+			return $this->objectPrefix.$fileId;
256 256
 		}
257 257
 		return null;
258 258
 	}
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
 					} catch (NotFoundException $e) {
312 312
 						$this->logger->logException($e, [
313 313
 							'app' => 'objectstore',
314
-							'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
314
+							'message' => 'Could not get object '.$this->getURN($stat['fileid']).' for file '.$path,
315 315
 						]);
316 316
 						throw $e;
317 317
 					} catch (\Exception $ex) {
318 318
 						$this->logger->logException($ex, [
319 319
 							'app' => 'objectstore',
320
-							'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path,
320
+							'message' => 'Could not get object '.$this->getURN($stat['fileid']).' for file '.$path,
321 321
 						]);
322 322
 						return false;
323 323
 					}
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 			case 'wb+':
332 332
 				$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
333 333
 				$handle = fopen($tmpFile, $mode);
334
-				return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
334
+				return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) {
335 335
 					$this->writeBack($tmpFile, $path);
336 336
 				});
337 337
 			case 'a':
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 					file_put_contents($tmpFile, $source);
349 349
 				}
350 350
 				$handle = fopen($tmpFile, $mode);
351
-				return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
351
+				return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) {
352 352
 					$this->writeBack($tmpFile, $path);
353 353
 				});
354 354
 		}
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 
358 358
 	public function file_exists($path) {
359 359
 		$path = $this->normalizePath($path);
360
-		return (bool)$this->stat($path);
360
+		return (bool) $this->stat($path);
361 361
 	}
362 362
 
363 363
 	public function rename($source, $target) {
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 			} catch (\Exception $ex) {
410 410
 				$this->logger->logException($ex, [
411 411
 					'app' => 'objectstore',
412
-					'message' => 'Could not create object for ' . $path,
412
+					'message' => 'Could not create object for '.$path,
413 413
 				]);
414 414
 				throw $ex;
415 415
 			}
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 		}
455 455
 		// update stat with new data
456 456
 		$mTime = time();
457
-		$stat['size'] = (int)$size;
457
+		$stat['size'] = (int) $size;
458 458
 		$stat['mtime'] = $mTime;
459 459
 		$stat['storage_mtime'] = $mTime;
460 460
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		$stat['etag'] = $this->getETag($path);
466 466
 
467 467
 		$exists = $this->getCache()->inCache($path);
468
-		$uploadPath = $exists ? $path : $path . '.part';
468
+		$uploadPath = $exists ? $path : $path.'.part';
469 469
 
470 470
 		if ($exists) {
471 471
 			$fileId = $stat['fileid'];
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 		try {
478 478
 			//upload to object storage
479 479
 			if ($size === null) {
480
-				$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {
480
+				$countStream = CountWrapper::wrap($stream, function($writtenSize) use ($fileId, &$size) {
481 481
 					$this->getCache()->update($fileId, [
482 482
 						'size' => $writtenSize,
483 483
 					]);
@@ -500,12 +500,12 @@  discard block
 block discarded – undo
500 500
 				$this->getCache()->remove($uploadPath);
501 501
 				$this->logger->logException($ex, [
502 502
 					'app' => 'objectstore',
503
-					'message' => 'Could not create object ' . $urn . ' for ' . $path,
503
+					'message' => 'Could not create object '.$urn.' for '.$path,
504 504
 				]);
505 505
 			} else {
506 506
 				$this->logger->logException($ex, [
507 507
 					'app' => 'objectstore',
508
-					'message' => 'Could not update object ' . $urn . ' for ' . $path,
508
+					'message' => 'Could not update object '.$urn.' for '.$path,
509 509
 				]);
510 510
 			}
511 511
 			throw $ex; // make this bubble up
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 			$this->mkdir($to);
555 555
 
556 556
 			foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) {
557
-				$this->copyInner($child, $to . '/' . $child->getName());
557
+				$this->copyInner($child, $to.'/'.$child->getName());
558 558
 			}
559 559
 		} else {
560 560
 			$this->copyFile($sourceEntry, $to);
Please login to merge, or discard this patch.