/** * Updates the data * * The data argument is a readable stream resource. * * After a succesful put operation, you may choose to return an ETag. The * etag must always be surrounded by double-quotes. These quotes must * appear in the actual string you're returning. * * Clients may use the ETag from a PUT request to later on make sure that * when they update the file, the contents haven't changed in the mean * time. * * If you don't plan to store the file byte-by-byte, and you return a * different object on a subsequent GET you are strongly recommended to not * return an ETag, and just return null. * * @param resource $data * @throws Sabre_DAV_Exception_Forbidden * @return string|null */ public function put($data) { if (!\OC\Files\Filesystem::isUpdatable($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } // mark file as partial while uploading (ignored by the scanner) $partpath = $this->path . '.part'; \OC\Files\Filesystem::file_put_contents($partpath, $data); //detect aborted upload if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { if (isset($_SERVER['CONTENT_LENGTH'])) { $expected = $_SERVER['CONTENT_LENGTH']; $actual = \OC\Files\Filesystem::filesize($partpath); if ($actual != $expected) { \OC\Files\Filesystem::unlink($partpath); throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual); } } } // rename to correct path \OC\Files\Filesystem::rename($partpath, $this->path); //allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { if (\OC\Files\Filesystem::touch($this->path, $mtime)) { header('X-OC-MTime: accepted'); } } return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path); }
public function setUp() { parent::setUp(); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); \OC\Files\Filesystem::clearMounts(); //login \OC_User::createUser('test', 'test'); \OC::$server->getSession()->set('user_id', 'test'); $this->storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::init('test', ''); \OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::mount($this->storage, array(), '/'); \OC\Files\Filesystem::file_put_contents('file1', self::CONTENT); $this->config->method('getAvChunkSize')->willReturn('1024'); }
/** * Creates a new file in the directory * * Data will either be supplied as a stream resource, or in certain cases * as a string. Keep in mind that you may have to support either. * * After succesful creation of the file, you may choose to return the ETag * of the new file here. * * The returned ETag must be surrounded by double-quotes (The quotes should * be part of the actual string). * * If you cannot accurately determine the ETag, you should not return it. * If you don't store the file exactly as-is (you're transforming it * somehow) you should also not return an ETag. * * This means that if a subsequent GET to this new file does not exactly * return the same contents of what was submitted here, you are strongly * recommended to omit the ETag. * * @param string $name Name of the file * @param resource|string $data Initial payload * @throws Sabre_DAV_Exception_Forbidden * @return null|string */ public function createFile($name, $data = null) { if (!\OC\Files\Filesystem::isCreatable($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } if (isset($_SERVER['HTTP_OC_CHUNKED'])) { $info = OC_FileChunking::decodeName($name); if (empty($info)) { throw new Sabre_DAV_Exception_NotImplemented(); } $chunk_handler = new OC_FileChunking($info); $chunk_handler->store($info['index'], $data); if ($chunk_handler->isComplete()) { $newPath = $this->path . '/' . $info['name']; $chunk_handler->file_assemble($newPath); return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } } else { $newPath = $this->path . '/' . $name; // mark file as partial while uploading (ignored by the scanner) $partpath = $newPath . '.part'; \OC\Files\Filesystem::file_put_contents($partpath, $data); //detect aborted upload if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { if (isset($_SERVER['CONTENT_LENGTH'])) { $expected = $_SERVER['CONTENT_LENGTH']; $actual = \OC\Files\Filesystem::filesize($partpath); if ($actual != $expected) { \OC\Files\Filesystem::unlink($partpath); throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual); } } } // rename to correct path \OC\Files\Filesystem::rename($partpath, $newPath); // allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { if (\OC\Files\Filesystem::touch($newPath, $mtime)) { header('X-OC-MTime: accepted'); } } return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } return null; }
public function setUp() { parent::setUp(); $this->userBackend = new \Test\Util\User\Dummy(); \OC::$server->getUserManager()->registerBackend($this->userBackend); $this->ownerUid = $this->getUniqueID('owner_'); $this->recipientUid = $this->getUniqueID('recipient_'); $this->userBackend->createUser($this->ownerUid, ''); $this->userBackend->createUser($this->recipientUid, ''); $this->loginAsUser($this->ownerUid); Filesystem::mkdir('/foo'); Filesystem::file_put_contents('/foo/bar.txt', 'asd'); $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId(); \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31); $this->loginAsUser($this->recipientUid); $this->assertTrue(Filesystem::file_exists('bar.txt')); }
public function testNewUser() { $user1 = $this->getUniqueID('user_'); $this->userBackend->createUser($user1, ''); $this->loginAsUser($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); $originalEtags = $this->getEtags($files); $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); // loop over array and use assertSame over assertEquals to prevent false positives foreach ($originalEtags as $file => $originalEtag) { $this->assertSame($originalEtag, $newEtags[$file]); } }
public function testNewUser() { $user1 = uniqid('user_'); $this->userBackend->createUser($user1, ''); \OC_Util::tearDownFS(); \OC_User::setUserId($user1); \OC_Util::setupFS($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); Filesystem::file_put_contents('/folder/bar.txt', 'fgh'); Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl'); $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); $originalEtags = $this->getEtags($files); $scanner = new \OC\Files\Utils\Scanner($user1); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); // loop over array and use assertSame over assertEquals to prevent false positives foreach ($originalEtags as $file => $originalEtag) { $this->assertSame($originalEtag, $newEtags[$file]); } }
\OC\Files\Filesystem::mkdir($dir); if (!\OC\Files\Filesystem::touch($dir . '/' . $file)) { OCP\JSON::error(array("data" => array("message" => "Error when creating new file!"))); OCP\Util::writeLog('files_svgedit', "Failed to create file: " . $path, OC_Log::ERROR); exit; } } // file should be existing now $writable = \OC\Files\Filesystem::isUpdatable($path); if ($writable) { if ($b64encoded) { $b64prefix = 'data:' . $b64type . ';base64,'; if (strpos($filecontents, $b64prefix) === 0) { $filecontents = base64_decode(substr($filecontents, strlen($b64prefix))); } } \OC\Files\Filesystem::file_put_contents($path, $filecontents); // Clear statcache clearstatcache(); // Get new mtime $newmtime = \OC\Files\Filesystem::filemtime($path); OCP\JSON::success(array('data' => array('mtime' => $newmtime))); } else { // Not writable! OCP\JSON::error(array('data' => array('message' => 'Insufficient permissions'))); OCP\Util::writeLog('files_svgedit', "User does not have permission to write to file: " . $path, OC_Log::ERROR); } } else { OCP\JSON::error(array('data' => array('message' => 'File path or mtime not supplied'))); OCP\Util::writeLog('files_svgedit', "Invalid path supplied:" . $path, OC_Log::ERROR); }
function testCopy() { \OC\Files\Filesystem::file_put_contents("test.txt", "test file"); $t1 = time(); // second version is two weeks older, this way we make sure that no // version will be expired $t2 = $t1 - 60 * 60 * 24 * 14; // create some versions $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; $v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; $v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; $this->rootView->file_put_contents($v1, 'version1'); $this->rootView->file_put_contents($v2, 'version2'); // execute copy hook of versions app \OC\Files\Filesystem::copy("test.txt", "test2.txt"); $this->assertTrue($this->rootView->file_exists($v1)); $this->assertTrue($this->rootView->file_exists($v2)); $this->assertTrue($this->rootView->file_exists($v1Copied)); $this->assertTrue($this->rootView->file_exists($v2Copied)); //cleanup \OC\Files\Filesystem::unlink('test.txt'); \OC\Files\Filesystem::unlink('test2.txt'); }
public function testPostDeleteMeta() { $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ $hookNode = null; $this->root->listen('\\OC\\Files', 'postDelete', function ($node) use(&$hookNode, &$hookCalled) { $hookCalled = true; $hookNode = $node; }); Filesystem::file_put_contents('test.txt', 'asd'); $info = Filesystem::getFileInfo('test.txt'); Filesystem::unlink('test.txt'); $this->assertTrue($hookCalled); $this->assertEquals($hookNode->getId(), $info->getId()); }
public function testTouchWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); $this->assertTrue($cache2->inCache('foo.txt')); $folderCachedData = $this->cache->get('folder'); $substorageCachedData = $cache2->get(''); $fooCachedData = $cache2->get('foo.txt'); $cachedData = $cache2->get('foo.txt'); $time = 1371006070; $this->cache->put('folder', ['mtime' => $time - 100]); Filesystem::touch('folder/substorage/foo.txt', $time); $cachedData = $cache2->get('foo.txt'); $this->assertInternalType('string', $fooCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); $cachedData = $cache2->get(''); $this->assertInternalType('string', $substorageCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']); $cachedData = $this->cache->get('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); }
public function viewToNodeProviderCopyRename() { return [[function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::rename('source', 'target'); }, 'preRename'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::rename('source', 'target'); }, 'postRename'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::copy('source', 'target'); }, 'preCopy'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::copy('source', 'target'); }, 'postCopy']]; }
/** * Test whether versions are created when overwriting as share recipient */ public function testStoreVersionAsRecipient() { $this->loginAsUser(self::TEST_VERSIONS_USER); \OC\Files\Filesystem::mkdir('folder'); \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file'); $fileInfo = \OC\Files\Filesystem::getFileInfo('folder'); \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL); $this->loginAsUser(self::TEST_VERSIONS_USER2); $this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt'); }
public function testShareWithGroupUniqueName() { $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); \OC\Files\Filesystem::file_put_contents('test.txt', 'test'); $fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt'); $this->assertTrue(\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 23)); $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $items = \OCP\Share::getItemsSharedWith('file'); $this->assertSame('/test.txt', $items[0]['file_target']); $this->assertSame(23, $items[0]['permissions']); \OC\Files\Filesystem::rename('test.txt', 'new test.txt'); $items = \OCP\Share::getItemsSharedWith('file'); $this->assertSame('/new test.txt', $items[0]['file_target']); $this->assertSame(23, $items[0]['permissions']); $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); \OCP\Share::setPermissions('file', $items[0]['item_source'], $items[0]['share_type'], $items[0]['share_with'], 3); $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $items = \OCP\Share::getItemsSharedWith('file'); $this->assertSame('/new test.txt', $items[0]['file_target']); $this->assertSame(3, $items[0]['permissions']); }
/** * @dataProvider usersProvider */ function testMoveFileToFolder($userId) { $view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1); $filename = '/tmp-' . $this->getUniqueID(); $folder = '/folder' . $this->getUniqueID(); \OC\Files\Filesystem::mkdir($folder); // Save long data as encrypted file using stream wrapper $cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort); // Test that data was successfully written $this->assertInternalType('int', $cryptedFile); // Get file decrypted contents $decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename); $this->assertEquals($this->dataShort, $decrypt); $subFolder = $folder . '/subfolder' . $this->getUniqueID(); \OC\Files\Filesystem::mkdir($subFolder); // get the file info from previous created file $fileInfo = \OC\Files\Filesystem::getFileInfo($folder); $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo); // share the folder \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // check that the share keys exist $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // move the file into the subfolder as the test user self::loginHelper($userId); \OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename); self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // Get file decrypted contents $newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename); $this->assertEquals($this->dataShort, $newDecrypt); // check if additional share key for user2 exists $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // check that old keys were removed/moved properly $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // tear down \OC\Files\Filesystem::unlink($subFolder); \OC\Files\Filesystem::unlink($folder); }
$result['data'] = array('message' => (string) $l10n->t('Incorrect padname.')); OCP\JSON::error($result); exit; } if (!OCP\Util::isValidFileName($padname)) { $result['data'] = array('message' => (string) $l10n_files->t("Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); OCP\JSON::error($result); exit; } if (!\OC\Files\Filesystem::file_exists($dir . '/')) { $result['data'] = array('message' => (string) $l10n_files->t('The target folder has been moved or deleted.'), 'code' => 'targetnotfound'); OCP\JSON::error($result); exit; } // Add the extension only if padname doesn’t contain it if (substr($padname, -strlen(".{$ext}")) != ".{$ext}") { $filename = "{$padname}.{$ext}"; } $target = $dir . "/" . $filename; if (\OC\Files\Filesystem::file_exists($target)) { $result['data'] = array('message' => (string) $l10n_files->t('The name %s is already used in the folder %s. Please choose a different name.', [$filename, $dir])); OCP\JSON::error($result); exit; } $content = sprintf("[InternetShortcut]\nURL=%s", $url); if (\OC\Files\Filesystem::file_put_contents($target, $content)) { $meta = \OC\Files\Filesystem::getFileInfo($target); OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta))); exit; } OCP\JSON::error(array('data' => array('message' => $l10n_files->t('Error when creating the file'))));
/** * test if additional share keys are added if we move a folder to a shared parent * @medium */ function testMoveFolder() { $view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); $filename = '/tmp-' . uniqid(); $folder = '/folder' . uniqid(); \OC\Files\Filesystem::mkdir($folder); // Save long data as encrypted file using stream wrapper $cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort); // Test that data was successfully written $this->assertTrue(is_int($cryptedFile)); // Get file decrypted contents $decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename); $this->assertEquals($this->dataShort, $decrypt); $newFolder = '/newfolder/subfolder' . uniqid(); \OC\Files\Filesystem::mkdir('/newfolder'); // get the file info from previous created file $fileInfo = \OC\Files\Filesystem::getFileInfo('/newfolder'); $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the folder \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL); \OC\Files\Filesystem::rename($folder, $newFolder); // Get file decrypted contents $newDecrypt = \OC\Files\Filesystem::file_get_contents($newFolder . $filename); $this->assertEquals($this->dataShort, $newDecrypt); // check if additional share key for user2 exists $this->assertTrue($view->file_exists('files_encryption/share-keys' . $newFolder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // tear down \OC\Files\Filesystem::unlink($newFolder); \OC\Files\Filesystem::unlink('/newfolder'); }
/** * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem */ public static function file_put_contents($path, $data) { return \OC\Files\Filesystem::file_put_contents($path, $data); }
public function testReshareRecipientWritesToReshare() { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4); Filesystem::file_put_contents('/sub1/sub2/inside/asd.txt', 'bar'); $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->assertAllUnchaged(); }
public function testRenameWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); $view = new View('/' . self::$user . '/files'); $this->assertTrue($cache2->inCache('foo.txt')); $folderCachedData = $view->getFileInfo('folder'); $substorageCachedData = $cache2->get(''); $fooCachedData = $cache2->get('foo.txt'); Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt'); $this->assertFalse($cache2->inCache('foo.txt')); $this->assertTrue($cache2->inCache('bar.txt')); $cachedData = $cache2->get('bar.txt'); $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']); $mtime = $cachedData['mtime']; $cachedData = $cache2->get(''); $this->assertInternalType('string', $substorageCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']); // rename can cause mtime change - invalid assert // $this->assertEquals($mtime, $cachedData['mtime']); $cachedData = $view->getFileInfo('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); // rename can cause mtime change - invalid assert // $this->assertEquals($mtime, $cachedData['mtime']); }
/** * test expiration of old files in the trash bin until the max size * of the trash bin is met again */ public function testExpireOldFilesUtilLimitsAreMet() { // create some files \OC\Files\Filesystem::file_put_contents('file1.txt', 'file1'); \OC\Files\Filesystem::file_put_contents('file2.txt', 'file2'); \OC\Files\Filesystem::file_put_contents('file3.txt', 'file3'); // delete them so that they end up in the trash bin \OC\Files\Filesystem::unlink('file3.txt'); sleep(1); // make sure that every file has a unique mtime \OC\Files\Filesystem::unlink('file2.txt'); sleep(1); // make sure that every file has a unique mtime \OC\Files\Filesystem::unlink('file1.txt'); //make sure that files are in the trash bin $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertSame(3, count($filesInTrash)); $testClass = new TrashbinForTesting(); $sizeOfDeletedFiles = $testClass->dummyDeleteFiles($filesInTrash, -8); // the two oldest files (file3.txt and file2.txt) should be deleted $this->assertSame(10, $sizeOfDeletedFiles); $newTrashContent = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1); $this->assertSame(1, count($newTrashContent)); $element = reset($newTrashContent); $this->assertSame('file1.txt', $element['name']); }
public function testShareWithGroupUniqueName() { $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); \OC\Files\Filesystem::file_put_contents('test.txt', 'test'); $share = $this->share(\OCP\Share::SHARE_TYPE_GROUP, 'test.txt', self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE); $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP); $share = $shares[0]; $this->assertSame('/test.txt', $share->getTarget()); $this->assertSame(19, $share->getPermissions()); \OC\Files\Filesystem::rename('test.txt', 'new test.txt'); $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP); $share = $shares[0]; $this->assertSame('/new test.txt', $share->getTarget()); $this->assertSame(19, $share->getPermissions()); $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE); $this->shareManager->updateShare($share); $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP); $share = $shares[0]; $this->assertSame('/new test.txt', $share->getTarget()); $this->assertSame(3, $share->getPermissions()); }
public function testGetPathByIdDirectShare() { self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OC\Files\Filesystem::file_put_contents('test.txt', 'foo'); $info = \OC\Files\Filesystem::getFileInfo('test.txt'); \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\PERMISSION_ALL); \OC_Util::tearDownFS(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::file_exists('/test.txt')); list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test.txt'); /** * @var \OC\Files\Storage\Shared $sharedStorage */ $sharedCache = $sharedStorage->getCache(); $this->assertEquals('', $sharedCache->getPathById($info->getId())); }
public function testRecipientUploadInDirectReshare() { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); Filesystem::file_put_contents('/directReshare/test.txt', 'sad'); $this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER3]); $this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]); $this->assertAllUnchanged(); }
private function parserFileHandler($files, $userForSharing) { $saveFiles = ['file_fileid' => [], 'shared_with' => []]; if ($this->loginVirtualUser()) { $innerDir = date("Ymd", time()); foreach ($files as $file) { if (!\OC\Files\Filesystem::is_dir('/Talks')) { \OC\Files\Filesystem::mkdir('/Talks'); } if (!\OC\Files\Filesystem::is_dir('/Talks/' . $innerDir)) { \OC\Files\Filesystem::mkdir('/Talks/' . $innerDir); } if (is_file($file['tmpfile'])) { try { chmod($file['tmpfile'], 0755); } catch (\Exception $e) { } $filePathTo = '/Talks/' . $innerDir . '/' . $file['filename']; $fileInfoExist = \OC\Files\Filesystem::getFileInfo($filePathTo, false); if ($fileInfoExist) { $filePathTo = '/Talks/' . $innerDir . '/' . time() . '-' . $file['filename']; } $saved = \OC\Files\Filesystem::file_put_contents($filePathTo, file_get_contents($file['tmpfile'])); if ($saved) { unlink($file['tmpfile']); $saveFilesInfo = \OC\Files\Filesystem::getFileInfo($filePathTo); Helper::mailParserLoger('FILES INFO: ' . json_encode($saveFilesInfo)); $saveFiles['file_fileid'][] = $saveFilesInfo['fileid']; $saveFiles['shared_with'][] = $this->shareFileToUsers($saveFilesInfo, $userForSharing); //todo mails sands } } } } return $saveFiles; }
public function testGroupReShareSubFolderRecipientWrites() { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4); Filesystem::file_put_contents('/sub/file.txt', 'asd'); $this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->assertAllUnchanged(); }
public function saveNote($FOLDER, $name, $group, $content, $in_mtime) { $maxlength = 2621440; // 5 Megs (2 bytes per character) $now = new DateTime(); $mtime = $now->getTimestamp(); if ($in_mtime != 0) { $mtime = $in_mtime; } $uid = \OCP\User::getUser(); // First check to see if we're creating a new note, createNote handles all of this $id = $this->createNote($FOLDER, $name, $group); if ($id != -1) { if ($FOLDER != '') { $tmpfile = $FOLDER . "/" . $name . ".htm"; if ($group != '') { $tmpfile = $FOLDER . "/[" . $group . "] " . $name . ".htm"; } \OC\Files\Filesystem::file_put_contents($tmpfile, $content); if ($info = \OC\Files\Filesystem::getFileInfo($tmpfile)) { $mtime = $info['mtime']; } } $query = \OCP\DB::prepare("UPDATE *PREFIX*ownnote set note='', mtime=? WHERE uid=? and name=? and grouping=?"); $results = $query->execute(array($mtime, $uid, $name, $group)); $query = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote_parts WHERE id=?"); $results = $query->execute(array($id)); $contentarr = $this->splitContent($content); for ($i = 0; $i < count($contentarr); $i++) { $query = \OCP\DB::prepare("INSERT INTO *PREFIX*ownnote_parts (id, note) values (?,?)"); $results = $query->execute(array($id, $contentarr[$i])); } } return "DONE"; }
$result['data'] = array('message' => (string) $l10n->t('The target folder has been moved or deleted.'), 'code' => 'targetnotfound'); OCP\JSON::error($result); exit; } $target = $dir . '/' . $fileName; if (\OC\Files\Filesystem::file_exists($target)) { $result['data'] = array('message' => (string) $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($fileName, $dir))); OCP\JSON::error($result); exit; } $success = false; $templateManager = OC_Helper::getFileTemplateManager(); $mimeType = OC_Helper::getMimetypeDetector()->detectPath($target); $content = $templateManager->getTemplate($mimeType); try { if ($content) { $success = \OC\Files\Filesystem::file_put_contents($target, $content); } else { $success = \OC\Files\Filesystem::touch($target); } } catch (\Exception $e) { $result = ['success' => false, 'data' => ['message' => $e->getMessage()]]; OCP\JSON::error($result); exit; } if ($success) { $meta = \OC\Files\Filesystem::getFileInfo($target); OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta))); return; } OCP\JSON::error(array('data' => array('message' => $l10n->t('Error when creating the file'))));
/** * Test whether versions are created when overwriting as share recipient */ public function testStoreVersionAsRecipient() { $this->loginAsUser(self::TEST_VERSIONS_USER); \OC\Files\Filesystem::mkdir('folder'); \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder'); $share = \OC::$server->getShareManager()->newShare(); $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedBy(self::TEST_VERSIONS_USER)->setSharedWith(self::TEST_VERSIONS_USER2)->setPermissions(\OCP\Constants::PERMISSION_ALL); $share = \OC::$server->getShareManager()->createShare($share); $this->loginAsUser(self::TEST_VERSIONS_USER2); $this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt'); \OC::$server->getShareManager()->deleteShare($share); }
/** * @expectedException \Exception */ public function testShareNotOwner() { \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); \OC\Files\Filesystem::file_put_contents('foo.txt', 'bar'); $info = \OC\Files\Filesystem::getFileInfo('foo.txt'); \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); }
public function testGetPathByIdDirectShare() { self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OC\Files\Filesystem::file_put_contents('test.txt', 'foo'); $info = \OC\Files\Filesystem::getFileInfo('test.txt'); $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); $node = $rootFolder->get('test.txt'); $share = $this->shareManager->newShare(); $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE); $this->shareManager->createShare($share); \OC_Util::tearDownFS(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::file_exists('/test.txt')); list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test.txt'); /** * @var \OC\Files\Storage\Shared $sharedStorage */ $sharedCache = $sharedStorage->getCache(); $this->assertEquals('', $sharedCache->getPathById($info->getId())); }