1818use OCP \Files \Node ;
1919use OCP \BackgroundJob \IJobList ;
2020use Psr \Log \LoggerInterface ;
21+ use OCP \Files \NotFoundException ;
2122
2223use OCA \Google \AppInfo \Application ;
2324use OCA \Google \BackgroundJob \ImportDriveJob ;
@@ -318,7 +319,7 @@ private function createDirsUnder(array &$directoriesById, Node $currentFolder, s
318319 * @return ?int downloaded size, null if already existing
319320 */
320321 private function getFile (string $ accessToken , string $ userId , array $ fileItem , array $ directoriesById , Node $ topFolder ): ?int {
321- $ fileName = preg_replace ('/\// ' , '-slash- ' , $ fileItem ['name ' ]);
322+ $ fileName = preg_replace ('/\// ' , '-slash- ' , $ fileItem ['name ' ] ?? ' Untitled ' );
322323 if (isset ($ fileItem ['parents ' ]) && count ($ fileItem ['parents ' ]) > 0 && array_key_exists ($ fileItem ['parents ' ][0 ], $ directoriesById )) {
323324 $ saveFolder = $ directoriesById [$ fileItem ['parents ' ][0 ]]['node ' ];
324325 } else {
@@ -328,7 +329,15 @@ private function getFile(string $accessToken, string $userId, array $fileItem, a
328329 if (isset ($ fileItem ['webContentLink ' ])) {
329330 if (!$ saveFolder ->nodeExists ($ fileName )) {
330331 $ fileUrl = 'https://www.googleapis.com/drive/v3/files/ ' . $ fileItem ['id ' ] . '?alt=media ' ;
331- $ savedFile = $ saveFolder ->newFile ($ fileName );
332+ try {
333+ $ savedFile = $ saveFolder ->newFile ($ fileName );
334+ } catch (NotFoundException $ e ) {
335+ $ this ->logger ->warning (
336+ 'Google Drive error, can \'t create file " ' . $ fileName . '" in " ' . $ saveFolder ->getPath () . '" ' ,
337+ ['app ' => $ this ->appName ]
338+ );
339+ return null ;
340+ }
332341 $ resource = $ savedFile ->fopen ('w ' );
333342 $ res = $ this ->googleApiService ->simpleDownload ($ accessToken , $ userId , $ fileUrl , $ resource );
334343 if (!isset ($ res ['error ' ])) {
@@ -368,6 +377,15 @@ private function getFile(string $accessToken, string $userId, array $fileItem, a
368377 ];
369378 $ fileUrl = 'https://www.googleapis.com/drive/v3/files/ ' . $ fileItem ['id ' ] . '/export ' ;
370379 $ savedFile = $ saveFolder ->newFile ($ fileName );
380+ try {
381+ $ savedFile = $ saveFolder ->newFile ($ fileName );
382+ } catch (NotFoundException $ e ) {
383+ $ this ->logger ->warning (
384+ 'Google Drive error, can \'t create document file " ' . $ fileName . '" in " ' . $ saveFolder ->getPath () . '" ' ,
385+ ['app ' => $ this ->appName ]
386+ );
387+ return null ;
388+ }
371389 $ resource = $ savedFile ->fopen ('w ' );
372390 $ res = $ this ->googleApiService ->simpleDownload ($ accessToken , $ userId , $ fileUrl , $ resource , $ params );
373391 if (!isset ($ res ['error ' ])) {
0 commit comments