Example #1
0
 /**
  * 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;
 }
Example #2
0
 function testUnshareFromSelf()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $fileinfo = $this->view->getFileInfo($this->filename);
     $pathinfo = pathinfo($this->filename);
     $duplicate = '/' . $pathinfo['filename'] . ' (2).' . $pathinfo['extension'];
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup', 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($this->filename);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($duplicate);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::deleteGroup('testGroup');
 }
Example #3
0
 /**
  * @medium
  */
 function testUnshareChildren()
 {
     $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
     $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // one folder should be shared with the user
     $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
     $this->assertCount(1, $shares);
     // move shared folder to 'localDir'
     \OC\Files\Filesystem::mkdir('localDir');
     $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
     $this->assertTrue($result);
     \OC\Files\Filesystem::unlink('localDir');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // after the parent directory was deleted the share should be unshared
     $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
     $this->assertEmpty($shares);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // the folder for the owner should still exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
 }
Example #4
0
 /**
  * @medium
  */
 function testpreUnlink()
 {
     $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // one folder should be shared with the user
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertSame(1, count($sharedFolders));
     // move shared folder to 'localDir'
     \OC\Files\Filesystem::mkdir('localDir');
     $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
     $this->assertTrue($result);
     \OC\Files\Filesystem::unlink('localDir');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // after the parent directory was deleted the share should be unshared
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertTrue(empty($sharedFolders));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // the folder for the owner should still exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
 }
Example #5
0
 public function testUnshareFromSelf()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $share1 = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->filename, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     $share2 = $this->share(\OCP\Share::SHARE_TYPE_GROUP, $this->filename, self::TEST_FILES_SHARING_API_USER1, 'testGroup', \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($this->filename);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // both group share and user share should be gone
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->shareManager->deleteShare($share1);
     $this->shareManager->deleteShare($share2);
 }
Example #6
0
 public function viewToNodeProvider()
 {
     return [[function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'preWrite'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'postWrite'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'preCreate'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
     }, 'postCreate'], [function () {
         Filesystem::mkdir('test.txt');
     }, 'preCreate'], [function () {
         Filesystem::mkdir('test.txt');
     }, 'postCreate'], [function () {
         Filesystem::touch('test.txt');
     }, 'preTouch'], [function () {
         Filesystem::touch('test.txt');
     }, 'postTouch'], [function () {
         Filesystem::touch('test.txt');
     }, 'preCreate'], [function () {
         Filesystem::touch('test.txt');
     }, 'postCreate'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
         Filesystem::unlink('test.txt');
     }, 'preDelete'], [function () {
         Filesystem::file_put_contents('test.txt', 'asd');
         Filesystem::unlink('test.txt');
     }, 'postDelete'], [function () {
         Filesystem::mkdir('test.txt');
         Filesystem::rmdir('test.txt');
     }, 'preDelete'], [function () {
         Filesystem::mkdir('test.txt');
         Filesystem::rmdir('test.txt');
     }, 'postDelete']];
 }
Example #7
0
 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');
 }
Example #8
0
 /**
  * @dataProvider dataPaths
  */
 function testMkdirr($path, $expected)
 {
     self::setUpUsers();
     Helper::mkdirr($path, new \OC\Files\View('/' . self::TEST_ENCRYPTION_HELPER_USER1 . '/files'));
     // ignore the filename because we only check for the directories
     $dirParts = array_slice($expected, 0, -1);
     $expectedPath = implode('/', $dirParts);
     $this->assertTrue(\OC\Files\Filesystem::is_dir($expectedPath));
     // cleanup
     \OC\Files\Filesystem::unlink('/' . $expected[0]);
     self::cleanUpUsers();
 }
Example #9
0
 /**
  * @medium
  * @brief test delete file forever
  */
 function testPermanentDeleteFile()
 {
     // generate filename
     $filename = 'tmp-' . time() . '.txt';
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // check if key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename . '.key'));
     // check if share key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     // delete file
     \OC\FIles\Filesystem::unlink($filename);
     // check if file not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
     // check if key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename . '.key'));
     // check if share key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     // find created file with timestamp
     $query = \OC_DB::prepare('SELECT `timestamp`,`type` FROM `*PREFIX*files_trash`' . ' WHERE `id`=?');
     $result = $query->execute(array($filename))->fetchRow();
     $this->assertTrue(is_array($result));
     // build suffix
     $trashFileSuffix = 'd' . $result['timestamp'];
     // check if key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
     // check if share key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
     // get timestamp from file
     $timestamp = str_replace('d', '', $trashFileSuffix);
     // delete file forever
     $this->assertGreaterThan(0, \OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp));
     // check if key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/' . $filename . '.' . $trashFileSuffix));
     // check if key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
     // check if share key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
 }
Example #10
0
 /**
  * if a file gets unshared from self the etag for the recipients root should change
  */
 function testUnshareFromSelfFile()
 {
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     $beforeUnshareUser2 = \OC\Files\Filesystem::getFileInfo('');
     $etagBeforeUnshareUser2 = $beforeUnshareUser2->getEtag();
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $beforeUnshareUser3 = \OC\Files\Filesystem::getFileInfo('');
     $etagBeforeUnshareUser3 = $beforeUnshareUser3->getEtag();
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OC\Files\Filesystem::unlink($this->folder);
     $this->assertTrue($result);
     $afterUnshareUser2 = \OC\Files\Filesystem::getFileInfo('');
     $etagAfterUnshareUser2 = $afterUnshareUser2->getEtag();
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $afterUnshareUser3 = \OC\Files\Filesystem::getFileInfo('');
     $etagAfterUnshareUser3 = $afterUnshareUser3->getEtag();
     $this->assertTrue(is_string($etagBeforeUnshareUser2));
     $this->assertTrue(is_string($etagBeforeUnshareUser3));
     $this->assertTrue(is_string($etagAfterUnshareUser2));
     $this->assertTrue(is_string($etagAfterUnshareUser3));
     $this->assertTrue($etagBeforeUnshareUser2 !== $etagAfterUnshareUser2);
     $this->assertTrue($etagBeforeUnshareUser3 !== $etagAfterUnshareUser3);
 }
Example #11
0
 /**
  * user1 share file to a group and to a user2 in the same group. Then user2
  * unshares the file from self. Afterwards user1 should no longer see the
  * single user share to user2. If he re-shares the file to user2 the same target
  * then the group share should be used to group the item
  */
 public function testShareAndUnshareFromSelf()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     // share the file to group1 (user2 is a member of this group) and explicitely to user2
     \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_ALL);
     \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     // user1 should have to shared files
     $shares = \OCP\Share::getItemsShared('file');
     $this->assertSame(2, count($shares));
     // user2 should have two files "welcome.txt" and the shared file,
     // both the group share and the single share of the same file should be
     // grouped to one file
     \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
     $this->assertSame(2, count($dirContent));
     $this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
     // now user2 deletes the share (= unshare from self)
     \OC\Files\Filesystem::unlink($this->filename);
     // only welcome.txt should exists
     $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
     $this->assertSame(1, count($dirContent));
     $this->verifyDirContent($dirContent, array('welcome.txt'));
     // login as user1...
     \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // ... now user1 should have only one shared file, the group share
     $shares = \OCP\Share::getItemsShared('file');
     $this->assertSame(1, count($shares));
     // user1 shares a gain the file directly to user2
     \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     // user2 should see again welcome.txt and the shared file
     \Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
     $this->assertSame(2, count($dirContent));
     $this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
 }
Example #12
0
 public function testDeleteWithMountPoints()
 {
     $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('');
     Filesystem::unlink('folder/substorage/foo.txt');
     $this->assertFalse($cache2->inCache('foo.txt'));
     $cachedData = $cache2->get('');
     $this->assertInternalType('string', $substorageCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
     $this->assertGreaterThanOrEqual($substorageCachedData['mtime'], $cachedData['mtime']);
     $cachedData = $view->getFileInfo('folder');
     $this->assertInternalType('string', $folderCachedData['etag']);
     $this->assertInternalType('string', $cachedData['etag']);
     $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
     $this->assertGreaterThanOrEqual($folderCachedData['mtime'], $cachedData['mtime']);
 }
Example #13
0
 /**
  * @medium
  * test delete file
  */
 function testDeleteFile()
 {
     // generate filename
     $filename = 'tmp-' . uniqid() . '.txt';
     $filename2 = $filename . '.backup';
     // a second file with similar name
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename, $this->dataShort);
     $cryptedFile2 = file_put_contents('crypt:///' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     $this->assertTrue(is_int($cryptedFile2));
     // check if key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename . '.key'));
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2 . '.key'));
     // check if share key for admin exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename2 . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     // delete first file
     \OC\FIles\Filesystem::unlink($filename);
     // check if file not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
     // check if key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename . '.key'));
     // check if share key for admin not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     // check that second file still exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2));
     // check that key for second file still exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2 . '.key'));
     // check that share key for second file still exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/' . $filename2 . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
     // get files
     $trashFiles = $this->view->getDirectoryContent('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
     $trashFileSuffix = null;
     // find created file with timestamp
     foreach ($trashFiles as $file) {
         if (strncmp($file['path'], $filename, strlen($filename))) {
             $path_parts = pathinfo($file['name']);
             $trashFileSuffix = $path_parts['extension'];
         }
     }
     // check if we found the file we created
     $this->assertNotNull($trashFileSuffix);
     // check if key for admin not exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
     // check if share key for admin not exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
 }
Example #14
0
<?php

/*
 * delete_results
 * Created on: Jan 30, 2013 12:30:40 PM
 * 
 * Copyright 2013 EnginSoft S.p.A.
 * All rights reserved
 */
include_once 'neurocloud/lib/common.php';
$study = $_POST["study"];
$jobid = $_POST["jobid"];
$path = "{$study}/results/{$jobid}";
$jobinfo = get_job_info($study, $jobid);
$usedspace = isset($jobinfo["usedspace"]) ? $jobinfo["usedspace"] : "undefined";
insert_job_log($study, $jobid, "deleted results. Used disk space: {$usedspace}");
if (\OC\Files\Filesystem::is_dir($path)) {
    //rmdirr($path);
    \OC\Files\Filesystem::unlink($path);
    // from Owncloud 5.0.0, this will recurse on subdirs (delTree)
}
$execdir = get_job_exec_dir($jobid);
if (is_dir($execdir)) {
    rmdirr($execdir);
}
exit;
Example #15
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function add()
 {
     \OCP\JSON::setContentTypeHeader('application/json');
     if (isset($_POST['FILE']) && strlen(trim($_POST['FILE'])) > 0 && (Tools::CheckURL($_POST['FILE']) || Tools::CheckFilepath($this->TorrentsFolder . '/' . $_POST['FILE'])) && isset($_POST['OPTIONS'])) {
         try {
             if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) {
                 throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol'));
             }
             $Target = Tools::CleanString(str_replace('.torrent', '', $_POST['FILE']));
             $OPTIONS = array('dir' => rtrim($this->AbsoluteDownloadsFolder, '/') . '/' . $Target, 'seed-ratio' => $this->BTRatioToReach, 'seed-time' => $this->SeedTime);
             // If target file exists, create a new one
             if (!\OC\Files\Filesystem::is_dir(rtrim($this->DownloadsFolder, '/') . '/' . $Target)) {
                 // Create the target file
                 \OC\Files\Filesystem::mkdir(rtrim($this->DownloadsFolder, '/') . '/' . $Target);
             } else {
                 $OPTIONS['bt-hash-check-seed'] = true;
                 $OPTIONS['check-integrity'] = true;
             }
             if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) {
                 $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K';
             }
             if (!is_null($this->BTMaxUploadSpeed) && $this->BTMaxUploadSpeed > 0) {
                 $OPTIONS['max-upload-limit'] = $this->BTMaxUploadSpeed . 'K';
             }
             if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
                 $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
                 if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
                     $OPTIONS['all-proxy-user'] = $this->ProxyUser;
                     $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
                 }
             }
             $AddTorrent = Aria2::AddTorrent(base64_encode(file_get_contents(rtrim($this->AbsoluteTorrentsFolder, '/') . '/' . $_POST['FILE'])), array(), array('Params' => $OPTIONS));
             if (isset($AddTorrent['result']) && !is_null($AddTorrent['result'])) {
                 $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
                 if ($this->DbType == 1) {
                     $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
                 }
                 $Query = \OCP\DB::prepare($SQL);
                 $Result = $Query->execute(array($this->CurrentUID, $AddTorrent['result'], $Target, 'BitTorrent', 1, time()));
                 if (isset($_POST['OPTIONS']['BTRMTorrent']) && strcmp($_POST['OPTIONS']['BTRMTorrent'], "true") == 0) {
                     \OC\Files\Filesystem::unlink($this->TorrentsFolder . '/' . $_POST['FILE']);
                 }
                 sleep(1);
                 $Status = Aria2::TellStatus($AddTorrent['result']);
                 $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
                 return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddTorrent['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress) . ' - ' . $this->L10N->t('Seeders') . ': ' . $Status['result']['numSeeders'], 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => 'BitTorrent', 'ISTORRENT' => true));
             } else {
                 return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?')));
             }
         } catch (Exception $E) {
             return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
         }
     } else {
         return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL or filepath you\'ve just provided')));
     }
 }
Example #16
0
 /**
  * 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');
 }
Example #17
0
 /**
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  */
 public static function unlink($path)
 {
     return \OC\Files\Filesystem::unlink($path);
 }
Example #18
0
 /**
  * Delete the current file
  *
  * @return void
  * @throws Sabre_DAV_Exception_Forbidden
  */
 public function delete()
 {
     if (!\OC\Files\Filesystem::isDeletable($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     \OC\Files\Filesystem::unlink($this->path);
 }
Example #19
0
 /**
  * Delete the current file
  *
  * @return void
  * @throws Sabre_DAV_Exception_Forbidden
  */
 public function delete()
 {
     if ($this->path === 'Shared') {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     if (!\OC\Files\Filesystem::isDeletable($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     \OC\Files\Filesystem::unlink($this->path);
     // remove properties
     $this->removeProperties();
 }
Example #20
0
<?php

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get data
$dir = stripslashes($_POST["dir"]);
$files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
$files = json_decode($files);
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if ($dir === '' && $file === 'Shared' || \OC\Files\Filesystem::file_exists($dir . '/' . $file) && !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
// get array with updated storage stats (e.g. max file size) after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
if ($success) {
    OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
} else {
    OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
}
Example #21
0
\OC::$session->close();
// Get data
$dir = stripslashes($_POST["dir"]);
$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
// delete all files in dir ?
if ($allFiles === 'true') {
    $files = array();
    $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
    foreach ($fileList as $fileInfo) {
        $files[] = $fileInfo['name'];
    }
} else {
    $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
    $files = json_decode($files);
}
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) && !(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) && \OC\Files\Filesystem::unlink($dir . '/' . $file))) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
// get array with updated storage stats (e.g. max file size) after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
if ($success) {
    OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
} else {
    OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
}
Example #22
0
\OC::$server->getSession()->close();
// Get data
$dir = stripslashes($_POST["dir"]);
$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
// delete all files in dir ?
if ($allFiles === 'true') {
    $files = array();
    $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
    foreach ($fileList as $fileInfo) {
        $files[] = $fileInfo['name'];
    }
} else {
    $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
    $files = json_decode($files);
}
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) && !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
// get array with updated storage stats (e.g. max file size) after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
if ($success) {
    OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
} else {
    OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
}
 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 testReshareRecipientDeleteInReShare()
 {
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
     Filesystem::unlink('/sub1/sub2/inside/file.txt');
     $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->assertAllUnchanged();
 }
Example #25
0
 public function deleteNote($FOLDER, $name, $group)
 {
     $now = new DateTime();
     $mtime = $now->getTimestamp();
     $uid = \OCP\User::getUser();
     $query = \OCP\DB::prepare("UPDATE *PREFIX*ownnote set note='', deleted=1, mtime=? WHERE uid=? and name=? and grouping=?");
     $results = $query->execute(array($mtime, $uid, $name, $group));
     $query = \OCP\DB::prepare("SELECT id FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
     $results = $query->execute(array($uid, $name, $group))->fetchAll();
     foreach ($results as $result) {
         $query2 = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote_parts WHERE id=?");
         $results2 = $query2->execute(array($result['id']));
     }
     if ($FOLDER != '') {
         $tmpfile = $FOLDER . "/" . $name . ".htm";
         if ($group != '') {
             $tmpfile = $FOLDER . "/[" . $group . "] " . $name . ".htm";
         }
         if (\OC\Files\Filesystem::file_exists($tmpfile)) {
             \OC\Files\Filesystem::unlink($tmpfile);
         }
     }
     return "DONE";
 }
Example #26
0
 /**
  * @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);
 }
Example #27
0
\OC::$session->close();
// Get data
$dir = stripslashes($_POST["dir"]);
$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
// delete all files in dir ?
if ($allFiles === 'true') {
    $files = array();
    $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
    foreach ($fileList as $fileInfo) {
        $files[] = $fileInfo['name'];
    }
} else {
    $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
    $files = json_decode($files);
}
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if ($dir === '' && $file === 'Shared' || !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
// get array with updated storage stats (e.g. max file size) after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
if ($success) {
    OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
} else {
    OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
}
Example #28
0
 /**
  * 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']);
 }
Example #29
0
function deleteNote($FOLDER, $id) {
	$TARGET=$FOLDER."/".$id;
	if (\OC\Files\Filesystem::file_exists($TARGET)) {
		\OC\Files\Filesystem::unlink($TARGET);
	}
	return "DONE";
}