Browse Source

Merge pull request #16038 from nextcloud/backport/15889/stable16

[stable16] handle storage exceptions when trying to set mtime
Roeland Jago Douma 4 years ago
parent
commit
870a330abb
2 changed files with 9 additions and 1 deletions
  1. 6 1
      lib/private/Files/View.php
  2. 3 0
      tests/lib/Files/ViewTest.php

+ 6 - 1
lib/private/Files/View.php

@@ -566,7 +566,12 @@ class View {
 			$hooks[] = 'create';
 			$hooks[] = 'write';
 		}
-		$result = $this->basicOperation('touch', $path, $hooks, $mtime);
+		try {
+			$result = $this->basicOperation('touch', $path, $hooks, $mtime);
+		} catch (\Exception $e) {
+			$this->logger->logException($e, ['level' => ILogger::INFO, 'message' => 'Error while setting modified time']);
+			$result = false;
+		}
 		if (!$result) {
 			// If create file fails because of permissions on external storage like SMB folders,
 			// check file exists and return false if not.

+ 3 - 0
tests/lib/Files/ViewTest.php

@@ -1962,6 +1962,9 @@ class ViewTest extends \Test\TestCase {
 		$operationArgs,
 		$path
 	) {
+		if ($operation === 'touch') {
+			$this->markTestSkipped("touch handles storage exceptions internally");
+		}
 		$view = new View('/' . $this->user . '/files/');
 
 		/** @var Temporary|\PHPUnit_Framework_MockObject_MockObject $storage */