*/
namespace OC\Files\Cache;
+
use OCP\Util;
/**
$scanner->scan($internalPath, Scanner::SCAN_SHALLOW);
$cache->correctFolderSize($internalPath);
self::correctFolder($path, $storage->filemtime($internalPath));
+ self::correctParentStorageMtime($storage, $internalPath);
}
}
$cache->remove($internalPath);
$cache->correctFolderSize($internalPath);
self::correctFolder($path, time());
+ self::correctParentStorageMtime($storage, $internalPath);
}
}
$cache->correctFolderSize($internalTo);
self::correctFolder($from, time());
self::correctFolder($to, time());
+ self::correctParentStorageMtime($storageFrom, $internalFrom);
+ self::correctParentStorageMtime($storageTo, $internalTo);
} else {
self::deleteUpdate($from);
self::writeUpdate($to);
$cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
self::correctFolder($parent, $time);
} else {
- Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR);
+ Util::writeLog('core', 'Path not in cache: ' . $internalPath, Util::ERROR);
}
}
}
}
+ /**
+ * update the storage_mtime of the parent
+ *
+ * @param \OC\Files\Storage\Storage $storage
+ * @param string $internalPath
+ */
+ static private function correctParentStorageMtime($storage, $internalPath) {
+ $cache = $storage->getCache();
+ $parentId = $cache->getParentId($internalPath);
+ $parent = dirname($internalPath);
+ if ($parentId != -1) {
+ $cache->update($parentId, array('storage_mtime' => $storage->filemtime($parent)));
+ }
+ }
+
/**
* @param array $params
*/
namespace Test\Files\Cache;
use \OC\Files\Filesystem as Filesystem;
+use OC\Files\Storage\Temporary;
class Updater extends \PHPUnit_Framework_TestCase {
/**
$this->assertEquals($time, $cachedData['mtime']);
}
+ public function testUpdatePermissionsOnRescanOnlyForUpdatedFile() {
+ $permissionsCache = $this->storage->getPermissionsCache();
+ $scanner = $this->storage->getScanner();
+ $scanner->scan('');
+ $cache = $this->storage->getCache();
+ $loggedInUser = \OC_User::getUser();
+ \OC_User::setUserId(self::$user);
+ FileSystem::getDirectoryContent('/');
+ $past = time() - 600;
+ $cache->put('', array('storage_mtime' => $past));
+
+ $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user));
+ $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.png'), self::$user));
+
+ $permissionsCache->set($cache->getId('foo.png'), self::$user, 15);
+ FileSystem::file_put_contents('/foo.txt', 'asd');
+
+ $this->assertEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user));
+ $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
+
+ FileSystem::getDirectoryContent('/');
+
+ $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
+
+ FileSystem::file_put_contents('/qwerty.txt', 'asd');
+ FileSystem::getDirectoryContent('/');
+
+ $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user));
+
+ \OC_User::setUserId($loggedInUser);
+ }
}