예제 #1
0
파일: trashbin.php 프로젝트: loulancn/core
 /**
  * Test restoring a file into a read-only folder, will restore
  * the file to root instead
  */
 public function testRestoreFileIntoReadOnlySourceFolder()
 {
     $userFolder = \OC::$server->getUserFolder();
     $folder = $userFolder->newFolder('folder');
     $file = $folder->newFile('file1.txt');
     $file->putContent('foo');
     $this->assertTrue($userFolder->nodeExists('folder/file1.txt'));
     $file->delete();
     $this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
     $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
     $this->assertCount(1, $filesInTrash);
     /** @var \OCP\Files\FileInfo */
     $trashedFile = $filesInTrash[0];
     // delete source folder
     list($storage, $internalPath) = $this->rootView->resolvePath('/' . self::TEST_TRASHBIN_USER1 . '/files/folder');
     if ($storage instanceof \OC\Files\Storage\Local) {
         $folderAbsPath = $storage->getSourcePath($internalPath);
         // make folder read-only
         chmod($folderAbsPath, 0555);
         $this->assertTrue(OCA\Files_Trashbin\Trashbin::restore('file1.txt.d' . $trashedFile->getMtime(), $trashedFile->getName(), $trashedFile->getMtime()));
         $file = $userFolder->get('file1.txt');
         $this->assertEquals('foo', $file->getContent());
         chmod($folderAbsPath, 0755);
     }
 }
예제 #2
0
OCP\JSON::callCheck();
\OC::$server->getSession()->close();
$files = $_POST['files'];
$dir = '/';
if (isset($_POST['dir'])) {
    $dir = rtrim((string) $_POST['dir'], '/') . '/';
}
$allFiles = false;
if (isset($_POST['allfiles']) && (string) $_POST['allfiles'] === 'true') {
    $allFiles = true;
    $list = array();
    $dirListing = true;
    if ($dir === '' || $dir === '/') {
        $dirListing = false;
    }
    foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir, \OCP\User::getUser()) as $file) {
        $fileName = $file['name'];
        if (!$dirListing) {
            $fileName .= '.d' . $file['mtime'];
        }
        $list[] = $fileName;
    }
} else {
    $list = json_decode($files);
}
$error = array();
$success = array();
$i = 0;
foreach ($list as $file) {
    $path = $dir . '/' . $file;
    if ($dir === '/') {
예제 #3
0
파일: trashbin.php 프로젝트: Romua1d/core
 /**
  * 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']);
 }