2727 * along with this program. If not, see <http://www.gnu.org/licenses/>
2828 *
2929 */
30+
3031namespace OC \Files \ObjectStore ;
3132
3233use Aws \S3 \Exception \S3Exception ;
@@ -177,63 +178,65 @@ public function getId() {
177178
178179 public function rmdir ($ path ) {
179180 $ path = $ this ->normalizePath ($ path );
181+ $ entry = $ this ->getCache ()->get ($ path );
180182
181- if (!$ this ->is_dir ($ path )) {
182- return false ;
183- }
184-
185- if (!$ this ->rmObjects ($ path )) {
183+ if (!$ entry || $ entry ->getMimeType () !== ICacheEntry::DIRECTORY_MIMETYPE ) {
186184 return false ;
187185 }
188186
189- $ this ->getCache ()->remove ($ path );
190-
191- return true ;
187+ return $ this ->rmObjects ($ entry );
192188 }
193189
194- private function rmObjects ($ path ) {
195- $ children = $ this ->getCache ()->getFolderContents ( $ path );
190+ private function rmObjects (ICacheEntry $ entry ): bool {
191+ $ children = $ this ->getCache ()->getFolderContentsById ( $ entry -> getId () );
196192 foreach ($ children as $ child ) {
197- if ($ child[ ' mimetype ' ] === ' httpd/unix-directory ' ) {
198- if (!$ this ->rmObjects ($ child[ ' path ' ] )) {
193+ if ($ child-> getMimeType () === ICacheEntry:: DIRECTORY_MIMETYPE ) {
194+ if (!$ this ->rmObjects ($ child )) {
199195 return false ;
200196 }
201197 } else {
202- if (!$ this ->unlink ($ child[ ' path ' ] )) {
198+ if (!$ this ->rmObject ($ child )) {
203199 return false ;
204200 }
205201 }
206202 }
207203
204+ $ this ->getCache ()->remove ($ entry ->getPath ());
205+
208206 return true ;
209207 }
210208
211209 public function unlink ($ path ) {
212210 $ path = $ this ->normalizePath ($ path );
213- $ stat = $ this ->stat ($ path );
211+ $ entry = $ this ->getCache ()-> get ($ path );
214212
215- if ($ stat && isset ($ stat ['fileid ' ])) {
216- if ($ stat ['mimetype ' ] === 'httpd/unix-directory ' ) {
217- return $ this ->rmdir ($ path );
218- }
219- try {
220- $ this ->objectStore ->deleteObject ($ this ->getURN ($ stat ['fileid ' ]));
221- } catch (\Exception $ ex ) {
222- if ($ ex ->getCode () !== 404 ) {
223- $ this ->logger ->logException ($ ex , [
224- 'app ' => 'objectstore ' ,
225- 'message ' => 'Could not delete object ' . $ this ->getURN ($ stat ['fileid ' ]) . ' for ' . $ path ,
226- ]);
227- return false ;
228- }
229- //removing from cache is ok as it does not exist in the objectstore anyway
213+ if ($ entry instanceof ICacheEntry) {
214+ if ($ entry ->getMimeType () === ICacheEntry::DIRECTORY_MIMETYPE ) {
215+ return $ this ->rmObjects ($ entry );
216+ } else {
217+ return $ this ->rmObject ($ entry );
230218 }
231- $ this ->getCache ()->remove ($ path );
232- return true ;
233219 }
234220 return false ;
235221 }
236222
223+ public function rmObject (ICacheEntry $ entry ): bool {
224+ try {
225+ $ this ->objectStore ->deleteObject ($ this ->getURN ($ entry ->getId ()));
226+ } catch (\Exception $ ex ) {
227+ if ($ ex ->getCode () !== 404 ) {
228+ $ this ->logger ->logException ($ ex , [
229+ 'app ' => 'objectstore ' ,
230+ 'message ' => 'Could not delete object ' . $ this ->getURN ($ entry ->getId ()) . ' for ' . $ entry ->getPath (),
231+ ]);
232+ return false ;
233+ }
234+ //removing from cache is ok as it does not exist in the objectstore anyway
235+ }
236+ $ this ->getCache ()->remove ($ entry ->getPath ());
237+ return true ;
238+ }
239+
237240 public function stat ($ path ) {
238241 $ path = $ this ->normalizePath ($ path );
239242 $ cacheEntry = $ this ->getCache ()->get ($ path );
@@ -557,7 +560,12 @@ public function getObjectStore(): IObjectStore {
557560 return $ this ->objectStore ;
558561 }
559562
560- public function copyFromStorage (IStorage $ sourceStorage , $ sourceInternalPath , $ targetInternalPath , $ preserveMtime = false ) {
563+ public function copyFromStorage (
564+ IStorage $ sourceStorage ,
565+ $ sourceInternalPath ,
566+ $ targetInternalPath ,
567+ $ preserveMtime = false
568+ ) {
561569 if ($ sourceStorage ->instanceOfStorage (ObjectStoreStorage::class)) {
562570 /** @var ObjectStoreStorage $sourceStorage */
563571 if ($ sourceStorage ->getObjectStore ()->getStorageId () === $ this ->getObjectStore ()->getStorageId ()) {
@@ -645,7 +653,13 @@ public function startChunkedWrite(string $targetPath): string {
645653 *
646654 * @throws GenericFileException
647655 */
648- public function putChunkedWritePart (string $ targetPath , string $ writeToken , string $ chunkId , $ data , $ size = null ): ?array {
656+ public function putChunkedWritePart (
657+ string $ targetPath ,
658+ string $ writeToken ,
659+ string $ chunkId ,
660+ $ data ,
661+ $ size = null
662+ ): ?array {
649663 if (!$ this ->objectStore instanceof IObjectStoreMultiPartUpload) {
650664 throw new GenericFileException ('Object store does not support multipart upload ' );
651665 }
@@ -656,7 +670,7 @@ public function putChunkedWritePart(string $targetPath, string $writeToken, stri
656670
657671 $ parts [$ chunkId ] = [
658672 'PartNumber ' => $ chunkId ,
659- 'ETag ' => trim ($ result ->get ('ETag ' ), '" ' )
673+ 'ETag ' => trim ($ result ->get ('ETag ' ), '" ' ),
660674 ];
661675 return $ parts [$ chunkId ];
662676 }
@@ -680,11 +694,11 @@ public function completeChunkedWrite(string $targetPath, string $writeToken): in
680694 $ stat ['mimetype ' ] = $ this ->getMimeType ($ targetPath );
681695 $ this ->getCache ()->update ($ stat ['fileid ' ], $ stat );
682696 }
683- } catch (S3MultipartUploadException | S3Exception $ e ) {
697+ } catch (S3MultipartUploadException | S3Exception $ e ) {
684698 $ this ->objectStore ->abortMultipartUpload ($ urn , $ writeToken );
685699 $ this ->logger ->logException ($ e , [
686700 'app ' => 'objectstore ' ,
687- 'message ' => 'Could not compete multipart upload ' . $ urn . ' with uploadId ' . $ writeToken
701+ 'message ' => 'Could not compete multipart upload ' . $ urn . ' with uploadId ' . $ writeToken,
688702 ]);
689703 throw new GenericFileException ('Could not write chunked file ' );
690704 }
0 commit comments