Exemplo n.º 1
0
 public function testTouchNotSupported()
 {
     $storage = new TemporaryNoTouch(array());
     $scanner = $storage->getScanner();
     \OC\Files\Filesystem::mount($storage, array(), '/test/');
     $past = time() - 100;
     $storage->file_put_contents('test', 'foobar');
     $scanner->scan('');
     $view = new \OC\Files\View('');
     $info = $view->getFileInfo('/test/test');
     $view->touch('/test/test', $past);
     $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
     $info2 = $view->getFileInfo('/test/test');
     $this->assertSame($info['etag'], $info2['etag']);
 }
Exemplo n.º 2
0
 public function testRenameCrossStoragePreserveMtime()
 {
     $storage1 = new Temporary(array());
     $storage2 = new Temporary(array());
     $scanner1 = $storage1->getScanner();
     $scanner2 = $storage2->getScanner();
     $storage1->mkdir('sub');
     $storage1->mkdir('foo');
     $storage1->file_put_contents('foo.txt', 'asd');
     $storage1->file_put_contents('foo/bar.txt', 'asd');
     \OC\Files\Filesystem::mount($storage1, array(), '/test/');
     \OC\Files\Filesystem::mount($storage2, array(), '/test/sub/storage');
     $view = new \OC\Files\View('');
     $time = time() - 200;
     $view->touch('/test/foo.txt', $time);
     $view->touch('/test/foo', $time);
     $view->touch('/test/foo/bar.txt', $time);
     $view->rename('/test/foo.txt', '/test/sub/storage/foo.txt');
     $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo.txt'));
     $view->rename('/test/foo', '/test/sub/storage/foo');
     $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo/bar.txt'));
 }
Exemplo n.º 3
0
 /**
  * rollback to an old version of a file.
  */
 public static function rollback($file, $revision)
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         list($uid, $filename) = self::getUidAndFilename($file);
         $users_view = new \OC\Files\View('/' . $uid);
         $files_view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files');
         $versionCreated = false;
         //first create a new version
         $version = 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename);
         if (!$users_view->file_exists($version)) {
             // disable proxy to prevent multiple fopen calls
             $proxyStatus = \OC_FileProxy::$enabled;
             \OC_FileProxy::$enabled = false;
             $users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename));
             // reset proxy state
             \OC_FileProxy::$enabled = $proxyStatus;
             $versionCreated = true;
         }
         // rollback
         if (@$users_view->rename('files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
             $files_view->touch($file, $revision);
             Storage::expire($file);
             return true;
         } else {
             if ($versionCreated) {
                 $users_view->unlink($version);
             }
         }
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * @medium
  */
 function testTouchFile()
 {
     $filename = '/tmp-' . uniqid();
     $view = new \OC\Files\View('/' . $this->userId . '/files');
     $view->touch($filename);
     // Save short data as encrypted file using stream wrapper
     $cryptedFile = $view->file_put_contents($filename, $this->dataShort);
     // Test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // Get file decrypted contents
     $decrypt = $view->file_get_contents($filename);
     $this->assertEquals($this->dataShort, $decrypt);
     // tear down
     $view->unlink($filename);
 }
Exemplo n.º 5
0
 /**
  * Rollback to an old version of a file.
  *
  * @param string $file file name
  * @param int $revision revision timestamp
  */
 public static function rollback($file, $revision)
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         // add expected leading slash
         $file = '/' . ltrim($file, '/');
         list($uid, $filename) = self::getUidAndFilename($file);
         $users_view = new \OC\Files\View('/' . $uid);
         $files_view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files');
         $versionCreated = false;
         //first create a new version
         $version = 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename);
         if (!$users_view->file_exists($version)) {
             $users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename));
             $versionCreated = true;
         }
         // rollback
         if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
             $files_view->touch($file, $revision);
             Storage::scheduleExpire($uid, $file);
             \OC_Hook::emit('\\OCP\\Versions', 'rollback', array('path' => $filename));
             return true;
         } else {
             if ($versionCreated) {
                 self::deleteVersion($users_view, $version);
             }
         }
     }
     return false;
 }
Exemplo n.º 6
0
 /**
  * rollback to an old version of a file.
  */
 public static function rollback($file, $revision)
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         list($uid, $filename) = self::getUidAndFilename($file);
         $users_view = new \OC\Files\View('/' . $uid);
         $files_view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files');
         $versionCreated = false;
         //first create a new version
         $version = 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename);
         if (!$users_view->file_exists($version)) {
             $users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename));
             $versionCreated = true;
         }
         // rollback
         if (@$users_view->rename('files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
             $files_view->touch($file, $revision);
             Storage::scheduleExpire($file);
             return true;
         } else {
             if ($versionCreated) {
                 self::deleteVersion($users_view, $version);
             }
         }
     }
     return false;
 }